wordpress how to query custom posts code example
Example 1: wp loop custom post type
<?php
$loop = new WP_Query(
array(
'post_type' => 'yourposttypehere'
'posts_per_page' => 50
)
);
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="col-sm-4">
My column content
</div>
<?php endwhile;
wp_reset_postdata();
?>
Example 2: query custom post type
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
);
$loop = new WP_Query($args);
while ( $loop->have_posts() ) {
$loop->the_post();
?>
<div class="entry-content">
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<?php
}
Example 3: wp_query custom post type
//WordPress: Query a custom post type
//For example, query all Case Study post types
<?php query_posts('post_type=case_studies'); ?>