WordPress.org

Support

Support » How-To and Troubleshooting » Latest comment post should be the first post in the blog

Latest comment post should be the first post in the blog

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

Viewing 1 replies (of 1 total)
  • Tara

    @t-p

    Volunteer Moderator

    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' );
Viewing 1 replies (of 1 total)
  • The topic ‘Latest comment post should be the first post in the blog’ is closed to new replies.