jeudi 15 octobre 2015

How to display posts using custom texonomy in wordpress?

I have installed Wp-Types plugin in my wordpress blog. I create a custom taxonomy called 'demo'. In which I have added two categories.

  • firstdemo
  • seconddemo

Now I want to show posts from this custom taxonomy so I am using this:

<?php


$custom_terms = get_terms('demo');

foreach($custom_terms as $custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'post',
        'tax_query' => array(
            array(
                'taxonomy' => 'demo',
                'field' => 'slug',
                'terms' => $custom_term->slug,
            ),
        ),
     );

     $loop = new WP_Query($args);
     if($loop->have_posts()) {
        echo '<h2>'.$custom_term->name.'</h2>';

        while($loop->have_posts()) : $loop->the_post();
            echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
        endwhile;
     }
}


?>

But its showing all posts who are using that taxonomy. I want to show posts from seconddemo. how to do it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire