I want to displaying only one new/current post per category in homepage. For example, there is 3 post with category A, and i want the old post from category A is replaced with the new post from category A in homepage, and the old post is just gone but not deleted. This also same for other categories.

I'm using pre_get_posts to approach this, but mine is just display one category only and the other is not.

Here's my code

function my_home_category( $query ) {
    if ( $query->is_home() ) {
        $query->set( 'cat', -1 );

        $query->set( 'posts_per_page', -1);
add_action( 'pre_get_posts', 'my_home_category' );

I know my code is not good, and i gladly appreciated any help that come to mind. thanks

  • You can't do this with a single query. You will need to get a list of categories, loop over them, and query 1 post from each, separately. Jan 4, 2019 at 9:20

1 Answer 1


As you are not comfortable with coding, you can try using Recent Posts Widget Extended plugin. It allows you to specify the number of posts per category that you want to be displayed.

Follow these steps:

  1. Install and activate the plugin.
  2. Head to Appearance > Widgets. Add Recent Posts Extended widget to your sidebar.
  3. The widget menu will expand to show its settings. Here, you can choose your desired category and specify the number of posts to show.
  4. Finally, click on the Save button to store your widget settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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