wp_query for custom taxonomy term
-
I have a custom post type named ‘tours’ and custom taxonomy named ‘tourtypes’ so i can categorize it into terms like ‘cultural tour’, ‘sports tour’ etc.
Need to tell u that i’m not the original author of this theme and i try to customise it so that instead of outputting all ‘tours’ post, user can also choose which tour category they want.
in the theme template taxonomy-tourtypes.php this is part of the code to display the term title:
<?php $terms = get_the_terms($post->ID, 'tourtypes'); foreach ($terms as $term){ ;?> <h2><?php echo $term->name; ?> Category</h2><?php } ;?>but i’m not sure whats wrong when trying to query the selected term
<?php $paged = get_query_string_paged(); $counter = 1; $termg = wp_get_post_terms($post->ID, 'tourtypes', array("fields" => "all")); $posts_per_page = get_option('theme_show_portfolio_items'); if($posts_per_page == "") { $posts_per_page = get_option('posts_per_page'); } $my_query = new WP_Query(array('post_type' => 'tours', 'tourtypes' =>'$termg' ,'paged' => $paged, 'posts_per_page' => $posts_per_page)); if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <?php $image = get_post_thumb($post->ID,280,180); ?> <li class="image"> <a href="<?php the_permalink();?>"><img src="<?php echo $image['src'];?>" alt="<?php the_title();?>" /></a> <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2> <?php global $more; // Declare global $more (before the loop). $more = 0; // Set (inside the loop) to display content above the more tag. ?> <?php add_filter('the_content', 'remove_images'); ?> <?php add_filter('the_content', 'remove_objects'); ?> <?php the_meta(); ?> <p><?php the_content(__('Book Now' , 'oxygen')); ?></p> </li> <?php if($counter%3 == 0) { ?> <li class="spacer"> </li> <?php } ?> <?php $counter++;?> <?php endwhile; else: ?> <?php endif; ?>I think i dont use proper code at the wp_query. anybody can point me to the right code?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘wp_query for custom taxonomy term’ is closed to new replies.