Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

get post by taxonomy

<?php
     $taxonomy = 'my_taxonomy'; // this is the name of the taxonomy
     $terms = get_terms($taxonomy);
     $args = array(
        'post_type' => 'post',
        'tax_query' => array(
                    array(
                        'taxonomy' => 'updates',
                        'field' => 'slug',
                        'terms' => wp_list_pluck($terms,'slug')
                    )
                )
        );

     $my_query = new WP_Query( $args );
     if($my_query->have_posts()) :
         while ($my_query->have_posts()) : $my_query->the_post();

              // do what you want to do with the queried posts

          endwhile;
     endif;
  ?>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #post #taxonomy
ADD COMMENT
Topic
Name
8+6 =