Grow your CSS skills. Land your dream job.

use wp_query to output taxonomy term post

  • # November 17, 2012 at 2:38 am

    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 do 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 (term) 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) { ;?>

    < ?php echo $term->name; ?> Category

    < ?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 directly 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

    # November 17, 2012 at 8:22 am

    anyone got any idea?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".