Skip to content

Instantly share code, notes, and snippets.

@uxmoon
Last active August 15, 2017 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uxmoon/6d22181f324db655b6cded68cf35f8b1 to your computer and use it in GitHub Desktop.
Save uxmoon/6d22181f324db655b6cded68cf35f8b1 to your computer and use it in GitHub Desktop.
WordPress Custom WP_Query
<?php

  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

  $args = array(
    'post_type' => 'press_article',
    'showposts' => '1',
    'paged'     => $paged,
  );

  $the_query = new WP_Query($args);

   if($the_query->have_posts()) :
      while($the_query->have_posts()) :
         $the_query->the_post();
?>

  <h2><?php the_title() ?></h2>

<?php
      endwhile;
   else:
?>

  <p>Oops, there are no posts.</p>

<?php
   endif;
?>  

Source:

  1. WordPress Codex
  2. Smashing Magazine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment