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!

@luissantander, could you share the “proper” method you ended up using in a bit more detail?

Sorry for reopening this thread, but I’m having the same problem and I can’t seem to find the “proper” method for shortcode insertion. I am able to insert the shortcode using the dynamic inserter on a cwicly paragraph block, but – as you also noted – that does not work with frontend rendering turned on (which I need for filtering).

When I try inserting the shortcode via the dynamic selector @Louis suggested, there’s no option to select shortcode as the source. Is it tucked away or do I need to enable it somewhere?

Would greatly appreciate any hint, thanks :slight_smile:

Cheers
Marc

Hi @marc, at first I just hardcoded the shortcode in a paragraph block, which worked on regular pages. But on a frontend rendering query, that didn’t work, instead you’re supposed to add a dynamic tag with the “+” icon and select Shortcode, and add it from there. Hope it’s clear!

Hi @luissantander thanks for reaching out so quickly!

Hm, that’s strange, I already tried that – with no luck, unfortuantely :frowning: With frontend rendering turned off, everything works fine. But with FR enabled, the cwicly paragraph block is empty on the frontend.

I also tried both methods of inserting shortcodes via the dynamic inserter showcased this post. The “old” one returns an empty paragraph and the “new” one crashes the whole query (no posts are displayed at all, querytemplate full of divs with class cc-loading-skeleton-top) returns the following error in my browser’s dev console:

[Error] Unhandled Promise Rejection: SyntaxError: The string did not match the expected pattern.
	promiseEmptyOnRejected
	promiseReactionJob

I’m kinda lost because I feel like I tried everything in my power, but I’m also new to queries with frontend rendering, so I’m probably missing something :smiley:

For you it worked fine without further adjustments, right @luissantander?

Cheers
Marc