Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is my first foray into custom post types and taxonomies. I created a taxonomy-services.php page to display posts that are associated with the 'websites' slug. That seems to be working fine.

However, I want to be able to show other posts on services.php that are associated with another slug, like 'video'.

These both fall under the Services taxonomy. I'm just not sure how to filter them on the services.php page.

Can someone please help me with this challenge. I'm both PHP/WordPress noob, and need to get a quick win on this one.

share|improve this question

1 Answer 1

you can check on your taxonomy-services.php what is the current queried term filter based on that, something like this:

//get the current term
$term_slug = get_query_var( 'term' );
//get the current taxonomy
$taxonomyName = get_query_var( 'taxonomy' );
//get the term object if you want
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );

//then you can query your posts/custom based on that term
$s_query = NEW WP_Query(array('services' => $term_slug, 'post_type' => 'post'));

//then you can simply filter the posts
if ($current_term->term_slug == "websites"){
   while($s_query->have_posts){
      $s_query->the_post();
      //do websites loop
   }
}elseif ($current_term->term_slug == "video"){
   while($s_query->have_posts){
      $s_query->the_post();
      //do videos loop
   }
}else{
   while($s_query->have_posts){
      $s_query->the_post();
      //do any other loop of that taxonomy
   }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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