Skip to content

Instantly share code, notes, and snippets.

@matgargano
Forked from ckschmieder/customloop.php
Last active August 24, 2016 15:18
Show Gist options
  • Save matgargano/99657a4896c8c6a3074d6867c6d18153 to your computer and use it in GitHub Desktop.
Save matgargano/99657a4896c8c6a3074d6867c6d18153 to your computer and use it in GitHub Desktop.
Want to loop thu PAGES with the category slug 'behavior'
<?php
global $post;
$my_query_args = array(
'posts_per_page' => -1, // change this to any number or '0' for all
'post_type' => 'page',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'behavior',
)
)
);
// a new instance of the WP_query class
$my_query = new WP_Query( $my_query_args );
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php endwhile; endif; wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment