1

I was wondering if someone could help me out. I have created a custom query to retrieve in a custom single.php to retrieve posts which have the same custom taxonomy term and display them. here is the query:

    <?php  
    $terms = wp_get_post_terms( $post->ID, 'customtaxonomy' );
    if($terms){
      // post has course_type terms attached
      $product_terms = array();
      foreach ($terms as $term){
       $product_terms[] = $term->slug;
      }

     $original_query = $wp_query;
     $wp_query = null;
     $wp_query = new WP_Query( array(
     'post_type' => 'customposttype',
     'tax_query' => array(
      array(
     'taxonomy' => 'customtaxonomy',
     'field' => 'slug',
     'terms' => $customtaxonomy_terms, //the taxonomy terms I'd like to dynamically query
     'posts_per_page' => '6'
        ),
      ),
      'orderby' => 'title',
      'order' => 'ASC'
      ) );



if ( have_posts() ): ?>


//display what you want in loop here.



<?php endwhile; ?>

within that query i would like to have a multiple conditional statement so that if a term='term 1'display specific image.

<?php

        foreach ( $terms as $term ) {
            if($term->name == 'customtermincustomtaxonomy') {
               show image
            }
        }
 ?>

I know i could easy use a if/else statement but that would only allow me to have 2 conditions. I know I should use an else if statement but i have not used php in a while and am having some problems formatting it. I appreciate the help.

1 Answer 1

0

Use the Switch statement.

switch ($term->name) {
    case 'customtermincustomtaxonomy':
        // ...
        break;
    case 'anotherterm':
        // ...
        break;
    case 'somethingelse':
        // ...
        break;
}
1
  • totally forgot about that thanks lol. I appreciate it!
    – steamfunk
    Mar 28, 2015 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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