Frontend rendering and return function

I have a query with frontend rendering turned on, because it uses a few filters to modify the query.

I need to modify some of the output (basically “number_format” the value of an ACF field). I’m using a return function in a paragraph.

When the query has frontend rendering it doesn’t execute the code. Setting it off lets me execute the code but the filters don’t work.

Am I doing something wrong? Any help appreciated.

Hey @luissantander.

This might solve your issue:

Please let me know if you got it to work.

Ah, thanks, close! I enabled that before to display the values at all, but it doesn’t help with the execution of the code snippets in frontend rendering. I’m sure I’m missing something. Appreciate the help.

Hello @luissantander,

You might want to use a shortcode instead and then whitelist it with this:

We currently don’t allow return functions for security reasons.
Frontend rendering will be revised in the future, but currently shortcodes are the best solution.

Hope that helps!

Thanks a million @Louis that helps!

Cheers

Ah, it’s still not working for me. On a query with frontend rendering, not rendered.

Work fine on an inner page:
Screenshot 2024-08-19 at 2.13.39 PM

Filter code:

add_filter('cwicly/frontend/shortcodes_whitelist', function ($array) {
        $array[] = 'vehicle_regular_price';
        $array[] = 'vehicle_financing_price';
        $array[] = 'vehicle_mileage';

    return $array;
});

Pretty sure I’m missing something. Any help appreciated.

Hello @luissantander,

Sorry to hear about this.

I appreciate it’s not as straightforward as it should be.
Can you try using this dynamic selector to display the shortcode instead of the dynamic inserter?

1 Like

Thanks for taking the time @Louis, indeed, it wasn’t working because I expected a paragraph with the shortcode written directly to work, so when using the “proper” shortcode insertion method it worked great.

I used a paragraph with the shortcode written directly in another instance (outside a query) and it worked, so I had that expectation.

Thanks again!