<?php $custom_query = new WP_Query('cat=9'); //your category id
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
//loop items go here
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
WordPress: Show all posts from specific category
-
10-07-2023 - |
سؤال
I Need to show latest post from a specified category in WordPress.
The category is " News World ", and I am try this code but show me all post from all category.
$wp_query = new WP_Query( array(
'post_type' => 'post',
'paged' => $paged
) );
المحلول 2
نصائح أخرى
Do this:
$wp_query = new WP_Query( array(
'post_type' => 'post',
'paged' => $paged,
'category_name' => 'News World'
) );
As per this reference. Note that you should NOT use the category name. You need the category SLUG. So make sure your category News World has slug "News World".
لا تنتمي إلى StackOverflow