Query Custom Post Type

Fundamental 117 views
0
0 Flares 0 Flares ×

If you use custom post types in your WordPress theme then you will eventually need this snippet. It allows you to query based on custom post type.

<?php 
if ( get_query_var('paged') ) $paged = get_query_var('paged');  
if ( get_query_var('page') ) $paged = get_query_var('page');

$query = new WP_Query( array( 'post_type' => 'books', 'paged' => $paged ) );

if ( $query->have_posts() ) : ?>

<?php while ( $query->have_posts() ) : $query->the_post(); ?>	
		<?php the_content(); ?>

<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
Tagged with: ,
Posted in Wordpress

Discuss:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×