Question

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
            ) );
Was it helpful?

Solution 2

<?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 ?>

OTHER TIPS

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".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top