Loop Specific Post-Type and Categories to a Specific Page |
X

Congrats, You are Subscribed to Receive Updates.

Loop Specific Post-Type and Categories to a Specific Page


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.

 

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

Comment Below

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

*

Current ye@r *

Menu

Sidebar