Loop Specific Post-Type and Categories to a Specific Page
- Article
- Comment
When you are creating custom post types, Surely you need to show it on a specific page and you need some short of sorting s and arrangement. Now you can set your custom template for custom post type. By the specific template, just query your desired post type and category with some additional parameters .
Here is a sample code for querying of a specific post types and categories,
$kv_loop = new WP_Query( array( 'post_type' => 'demo', // or whatever is called your custom post type 'cat' => 2, // or whatever is the "id" for your custom post type category 'posts_per_page' => 10 ) ); if ( $kv_loop->have_posts() ) : while ( $kv_loop->have_posts() ) : $kv_loop->the_post(); // here your code. } endwhile; endif;
The above example i used demo as a custom post type and queried based on the custom post type with category id, you can specify your category slug or Id, Either in single or an array of categories. This is a simple way of querying posts and display on your selected custom template.