WordPress.org

Forums

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

  1. bloggingandwb
    Member
    Posted 9 months 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
    Member
    Posted 9 months 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' );

Reply

You must log in to post.

About this Topic

Tags