Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

I'm not the original author of this theme and don not know much about dealing with taxonomy. But I want to extend 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 which work:

<?php $terms = get_the_terms($post->ID, 'tourtypes'); foreach ($terms as $term){ ;?>
<h2><?php echo $term->name; ?> Category</h2><?php } ;?>

But when it comes to the part where i want to query the specified term it didnt work.

<?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');
}

<?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));
  ...

I manage to get it to work if i type in the term slug eg.

$my_query = new WP_Query(array('post_type' => 'tours', 'tourtypes' =>'cultural' ...

I'm sure i just need a little change on the wp_query. Anyone care to point to the right code..i almost give up with this

share|improve this question
If you are using the default wp template hierarchy (which it looks like you are) you won't need any special WP query, WordPress will just know. So take a standard loop. Make a backup of that template, then add a normal WP look and see how you get on. It should be what you want. – Cristian Nov 17 '12 at 8:37

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.