I would like to get all the posts under a category (custom post type ui category) into a different template other than archive.php or category.php.

I tried normal way of getting the posts using category id, but it returns empty array. Please help.

  • why don't you share your code that you already tried ? – mlimon Oct 27 '16 at 22:41

Worked perfectly for me!! Code will bring the posts(under CPT UI) to any page template.

$loop = new WP_Query( array( 
    'post_type' => 'specialoffers', 
    'cat' => '12', // Whatever the category ID is for your aerial category
    'posts_per_page' =>  10,
    'orderby' => 'date', // Purely optional - just for some ordering
    'order' => 'DESC' // Ditto
) );

while ( $loop->have_posts() ) : $loop->the_post(); ?>
| improve this answer | |

custom post type ui category

It sounds like you might be referring to a custom taxonomy that you created with the "Custom Post Type UI" plugin. If that's the case, then you'll need to use a taxonomy template: taxonomy.php.

Wordpress Template Hierarchy

category.php and tag.php are only used for the built-in "category" and "tag" taxonomies.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.