Query string for the same term in a custom taxonomy


I built a CPT (actividad) which has a custom taxonomy attached (localizacion). I have a loop provider set up in a row in the Actividad layout, but I want it to only display the posts that have the same “localizacion” value as the current post. How can I built that query string?

I tried to customize an answer given by @friech some days ago (Can a range of posts be displayed depending the current post being viewed?) with this result:


but I keep getting an empty row. Any help?

Thanks, Sergio

1 Like

Hello Sergio,

Thanks for writing to us.

It seems that the code is working fine at my end in order to help you with your concern we need to check your settings. Please share your details in a secure note. Please provide the following details

  • WordPress Login URL
  • Admin level username and password
  • Exact Page URL

You can find the Secure Note button at the bottom of your posts


Secure note added, thanks a lot,

Hi Sergio,

It seems that the Query String is having the formatting issue, I would suggest you go through the following thread describing the Taxonomy query format and how to convert it as Query String.

Hope it helps.

I’m afraid I cannot get it to work… I just got


as the query string, but it won’t work. Any ideas?

Hi Sergio,

I have created the Query and generated the Query String as described in those reference threads. Please find the Query and the Query String below.

The Query:

$tax_query[] = array(
    'taxonomy' => 'localizacion',
    'field'    => 'slug',
    'terms'    => {{dc:term:slug}},
    'operator' => 'IN',

$query = array(
    'post_type'           => 'actividad',
    'post_status'         => 'publish',
    'ignore_sticky_posts' => 1,
    'posts_per_page'      => 6,
    'orderby'             => 'rand',
    'order'               => 'asc',
    'post__not_in'        => {{dc:post:id}},
    'tax_query'           => $tax_query

The Query String:


I would suggest you use the following Query String instead of the above one and check if that works for you.



Hi again
The second query string gets three posts from actividad, but they are not restricted to those sharing the same value in the localizacion taxonomy.
I also tried the first one, and it returns nothing.

Best regards,

Hello Sergio,

Kindly check out this old thread:

In your case, the query string can be:

Kindly let us know if this works out for you.

I’m afraid it doesn’t work either. Mind that I have two custom taxonomies defined for that CPT, and I think (correct me if I’m wrong) that {{dc:term:slug}} could refer to either one of those taxonomies.
Now I realize I didn’t bring up the two taxonomies thing earlier, sorry if that makes a difference in approach. I only want one of those (localizacion) to match the current post.

Thanks again,

Hi again
In any case, I’m going to solve this problem with a relationship on the ACF fields of the CPT. Anyway, it would be great to find a solution to find a way of using the custom taxonomy.

Best regards, Sergio

Hi Sergio,

I have checked it again and found that the {{dc:term:slug}} or {{dc:term:name}} is not showing the value and i.e. why the Query String is not able to find the localizacion for the specific Term.
I would suggest you update the Pro to its latest version 5.0.8, and check that if the Query String works.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.