Skip to:
Content
Pages
Categories
Search
Top
Bottom

Show Post on top


  • wlaurito
    Participant

    @wlaurito

    Hi!
    Is it possible to bring the last commented post to the top of the activity stream again?

Viewing 2 replies - 1 through 2 (of 2 total)

  • wlaurito
    Participant

    @wlaurito

    Someone?


    zimou13
    Participant

    @zimou13

    This solution is based on some code by Justin Tadlock. pre_get_posts is called before WordPress gets the posts of the main loop. Basically, you test to see if the page is the archive of the post type and make sure post_parent hasn’t been set. Then you set post_parent to 0, which is the default parent of top level posts. Easy as pie.
    <?php
    //pre_get_posts filter is called before WordPress gets posts
    add_filter( ‘pre_get_posts’, ‘my_get_posts’ );

    function my_get_posts( $query ) {
    //if page is an archive and post_parent is not set and post_type is the post type in question
    if ( is_archive() && false == $query->query_vars[‘post_parent’] && $query->query_vars[‘post_type’] == ‘my_post_type’)
    //set post_parent to 0, which is the default post_parent for top level posts
    $query->set( ‘post_parent’, 0 );
    return $query;
    }
    ?>
    see: https://showbox.onl/, https://vidmate.onl/ & https://mobdro.onl/

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar