FavoriteLoadingAdd to favorites

Calling your Query While or Foreach

While

<?php $query = new WP_Query($args); ?>
<?php while ( $query->have_posts() ) : the_post(); ?>
  <div>
      <?php 
      	$query->the_post();        
        get_template_part( 'content', get_post_format() ); 
    ?>
  </div>
<?php endwhile; ?>

Foreach

$query = new WP_Query( array( 'post_type' => 'page' ) );
$posts = $query->posts;

foreach($posts as $post) {
    // Do your stuff, e.g.
    // echo $post->post_name;
}

By Term

$args['tax_query'][] =
    array(
    'taxonomy' => 'category',
    'field' => 'slug',
    'terms' => 'category slug must go here'
  );

By Post Type

$args['post_type'] = 'courses';

By Post Status

$args['post_status'] = 'publish';

Posts Per Page

$args['posts_per_page'] = 10;

Posts By Category

$args['cat'] = $_GET['category-id'];

Pin It on Pinterest

Share This