How to set term field as a variable

I have a Custom Post called Testimonials. I have created a template to show this list.
However, there are many categories that are shown in different places on the website. I do not want to create a separate template for all categories, but rather just add the term name as a variable to the shortcode, like for example

[template id=3850 local_term=transporter]

(My loop looks like this: <Loop type=testimonials count=1 orderby=random category=target groups taxonomy=target group taxonomy_compare=and terms={Get local=local_term}>

Can you please tell me if this is possible, and how can I achieve this?

Thank you very much.

Hi Frans,
The example you provided is very very close to correct, your local variable tag just needs quotes around it and there seems to be a slight issue with your taxonomy name as those don’t generally have spaces in them. Finally, you shouldn’t need to define both taxonomy and category. If you’re using built in categories you can just pass your local variable containing the term slug or ID to the category parameter, and if you’re using a custom taxonomy then you can use the taxonomy and terms parameters :slight_smile:

<Loop type=testimonials count=1 orderby=random taxonomy="target_group" taxonomy_compare="and" terms="{Get local=local_term}">

Tag/shortcode attributes as variables in templates are covered in our documentation here: Template | Loops & Logic

You can learn more about the taxonomy loop parameters here: Post | Loops & Logic

Hi Julia,

Thank you so much for your help!

1 Like