I am working on a institute website which as courses.
I want to display all posts as list category wise of a custom post type.
for Ex.:
CATEGORY NAME1
– Post of category name 1
– Post of category name 1CATEGORY NAME2
– Post of category name 2
– Post of category name 2
and so on
below is the code which is displaying all posts from custom post type from all categories but i want to show them category wise seperately please help me…
<?php
$type = 'course';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1);
$my_query = '';
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query();
?>
you may need to do your query more than once, or one per category the key is adding ‘category_name’ => ‘slug_name’ to your query
100% working this code