How to get category wise all post in WordPress?
Add below code in taxonomy-"yourtaxonomyname".php
for ex : file name : taxonomy-event-category.php & Post type : events & taxonomy name : event-category
<?php
$category_object = get_queried_object();
$category_taxonomy = $category_object->taxonomy;
$category_term_id = $category_object->term_id;
$category_name = $category_object->name;
$category_description = $category_object->description;
$category_slug = $category_object->slug;
$post_type = 'events';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_args=array(
'type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 15,
'paged' => $paged,
'caller_get_posts' => -1,
'child_of' => 0,
'parent' => 0,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'tax_query' => array(
array(
'taxonomy' => $category_taxonomy,
'field' => 'id',
'terms' => $category_term_id
)
),
'pad_counts' => false,
);
$post_my_query = null;
$post_my_query = new WP_Query($post_args);
if( $post_my_query->have_posts() ) :
?>
<ul>
<?php
while ($post_my_query->have_posts()) : $post_my_query->the_post();
?>
<li>
<a href="<?php echo get_permalink($post->ID);?>">
<?php
if ( has_post_thumbnail() ) {
//get_the_post_thumbnail( $post->ID, array( 100, 100) );
?>
<?php echo get_the_post_thumbnail($post->ID,'medium'); //thumbnail,medium,large,full,array(100,100)?>
<?php
}
?>
<p><?php echo get_the_title( $post->ID );?></p>
</a>
</li>
<?php
endwhile;
?>
</ul>
<?php
else :
echo '<p class="red-error">No Post Found!</p>';
endif;
wp_reset_query($post_my_query);
?>
<?php //if(function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $post_my_query ) ); }else{ echo '<p class="red-error">No Event Post Found!</p>'; }
?>