Latest comment post should be the first post in the blog (2 posts)

  1. bloggingandwb
    Posted 2 years ago #

    If someone put a comment to post, that post should be the first post of blog. ( Forums works like this).

    I don't want to use forum plugin also. I need only, when a user submit a comment, that post goes to up as the first post of my blog.

    Is it possible?

  2. Tara
    Volunteer Moderator
    Posted 2 years ago #

    put this code in your active theme's functions.php

    function orderby_comment_count( $query ) {
        if ( $query->is_home() OR  $query->is_category()){
            if($query->is_main_query() AND !is_admin() ) {
                $query->set( 'orderby', 'comment_count' );
    add_action( 'pre_get_posts', 'orderby_comment_count' );

Topic Closed

This topic has been closed to new replies.

About this Topic