0

I made a cpt "Neighborhoods" for different neighborhoods.

On the Neighborhoods archive, you click on one and go to the single.

All good.

an example url is /blog/neighborhoods/south-austin/

But I'm trying to run a wp_query on that single looking for all properties in that are in that neighborhood.

I created a custom taxonomy called "prop_neighborhood" that I assigned to the "client_prop" cpt. I can call it manually like this:

$args = array(
  'post_type' => 'client_prop',
  'posts_per_page' => 10,
  'tax_query' => array(
   array(
    'taxonomy' => 'prop_neighborhood',
    'field' => 'slug',
    'terms' => 'south-austin',
    )
  )
);

But then I have make a template for each one. How can I make the "terms" pull in the current post title slug, save it as a variable and insert it where "south-austin" is?

I'm thinking this would be a good way to run it, as long as the page title url matches the taxonomy slug it will call it in correctly?

1

Does this work?

global $post;   // make sure the post object is available
$slug = $post->post_name;  // get the slug

// insert the slug into your query
$args = array(
  'post_type' => 'client_prop',
  'posts_per_page' => 10,
  'tax_query' => array(
   array(
    'taxonomy' => 'prop_neighborhood',
    'field' => 'slug',
    'terms' => $slug,
    )
  )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.