Dynamic Shortcode in Query Template?

Hello all!

Just wondering if there is anyway to render post-related data in a shortcode within the Query block?

For example, if I have this basic shortcode to display the post ID like this:

function test_shortcode_in_query() {
	$my_id = get_the_ID();	
	return 'My ID is: ' . $my_id;
}
add_shortcode('my_id', 'test_shortcode_in_query');

When I add this shortcode within the Query Template it currently returns the the same ID (the current post/page id) for all the posts/items in the Query.

Note that this is a super basic example for a dynamic shortcode - and I know I can display the ID using Cwicly “dynamic values” :slight_smile: But I have more complex shortcodes that pull in ACF data, manipulate it and creates outputs.

Cheers!
Jakson

Hi there @Jakson,

Great to see you on here :slight_smile:

Just tried this in a Query Template and it’s returning the correct ID on my side.
Are you using the latest Cwicly version?

Cheers,

Hey @Louis - glad to be here :slight_smile:

Yes, everything is all up to date

Thanks for the details.

Are the Cwicly dynamic options working correctly within the Query Template?

Can you try adding this as content to a (Cwicly) Paragraph/Heading block to see if it returns the correct one: {return=get_the_ID()}

Ah, hold tight! @Louis

I was using the Paragraph block - not the shortcode block - Doh!

All good now :slight_smile:

Just a little update on use of shortcodes that might be helpful:

The default Gutenberg Shortcode block is pretty clunky, gets in the way of your design in the editor and obvs has zero params for layout/spacing etc.

I reckon its better to use the Cwickly dynamic tag option to call your function (that I discovered today and is pretty epic!) - in my example function above, it would be:

{return=test_shortcode_in_query()}

Add a <p> and select its tag as <div> and it looks soo much neater on the edit page and no need to pass through a shortcode - nice!

1 Like

this is cool but i get more and more the feeling that we have to work with so many workarounds because the standard Cwicly UX doesnt deliver to accomplish such standard tasks out of the box or it is in making of…i mean if i am forced to use code snippets and pure WP queries and stuff like that to just grap my product categories then where is the benefit of a highliy sophisticated site editor right now?

@Timo, I’m not sure what this specifically refers to, but you can display your product categories via a Taxonomy Terms block.

Regarding:

If you have specific requirements I recommend letting the Cwicly team know as they are extremely reliable at delivering popular features. When you raise a separate feature request or question on the discourse it will usually be addressed very quickly.

Hi @StrangeTech

thanx yes i tried with “taxonomy terms” see below but no luck…nothing is outputted therefore i write my own WP Query and post it with a PHP Echo shortcode…that is what i meant for example…easy tasks which in my opinion must function if you want to run a dynamic site should not be part of a voting system …i think this is essential and it is also already there…but because Cwicly doesnt state if something doesnt work…it is just possible to click through all kinds of things but i am not sure if this is already part of the feasture list…so making it hard to accomnplish my tasks in a reliable time frame…

best wishes
timo

In order to preview the taxonomy terms in a template, Cwicly needs a context (i.e. a post) with which to show them for.

Please use the dynamic preview feature and select one of your products to be able to see an output.

Screenshot 2023-11-13 at 11.35.49