I just tested this out myself and it seems like you’re right that custom_field
and custom_field_value
don’t in fact exist as query parameters associated with a taxonomy term loop. I’m not familiar enough with how queries work in the backend of WordPress but it’s entirely possible that the mechanism that’s used by that query parameter when querying posts just doesn’t exist when querying taxonomy terms. If it were, I would assume it would have been included, since most of those query parameters are just piggybacking off existing PHP functions and weren’t all custom-built.
If you check out the Loop tag documentation you’ll see that there are also general-purpose attributes that you can use to filter your loop. Theoretically, they might be marginally less efficient than filtering your loop using query parameters, but they’re a lot more flexible. In your case, you could use field
and field_value
:
<Loop taxonomy=category
post=current
field=_yoast_wpseo_primary_category
field_value="{Shortcode primary_category_id}">
<Field sidebar_cta_title />
</Loop>
Remember that when you write a shortcode in L&L, you need to wrap it in a Shortcode
tag so that it gets processed instead of just being interpreted as plain text. I haven’t worked with that feature of Yoast so I can’t tell you if using that shortcode is the right approach, but I can answer this question:
You’ve got the right idea that the current post’s ID doesn’t exist within a taxonomy term loop. You can always use variables to pass data from one loop context to another.
<Set current_id><Field id /></Set>
<Loop type=category post=current>
<Field title />
<Get current_id />
</Loop>
On the other hand, if you’re trying to put the current post’s ID into the value of a query parameter, you can just do that with <Field id />
because until you actually open the loop, the context of the tag is still in the current post, not in the post loop. In other words, while you’re defining your loop, you haven’t actually started the loop and therefore you haven’t changed the loop context. So something like this should work to pass the current post’s ID to the value of the field_value
query parameter:
<Loop taxonomy=category
post=current
field=_yoast_wpseo_primary_category
field_value="{Field id}">
<Field sidebar_cta_title />
</Loop>