A
A
Andrey2018-05-22 21:19:13
WordPress
Andrey, 2018-05-22 21:19:13

Sort posts by latest comment?

<div id="loop">
        <?php $postcount=0; ?>
            <?php if ( have_posts() ) { $count = 0; while ( have_posts() ) { the_post(); $count++; ?>

        <?php get_template_part( 'content' ); ?>
        
            <?php
            		}
            	} else {
            ?>
                <div class="404">
                    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
                </div><!-- /.post -->
          
            <?php } ?>
        
        
        <div class="navigation">
          <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
        </div>
  
      </div>

There is such cycle of an output of records in archive. He is basically normal. Tell me how to make the entries displayed by the last comment - the entry where the most recent comment was at the top. By the principle of the forum.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-05-22
@dimasmagadan

Out of the box, WP doesn't do that.
I solved it like this:
1 hang a hook - when adding a comment, add / update a meta field with the current time to the parent post.
2 do sorting by this metafield

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question