• Resolved Leo.Lin

    (@bi1012037)



    When I set posts test10 and test9 as sticky posts, why does the sticky posts feature become ineffective when I choose to sort posts by their publication time?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Leo.Lin

    (@bi1012037)

    I modified 『Simple_Posts_Table.php』 and it worked successfully

    public function get_table( $args ) {
                    ...                
                    // Separate sticky and non-sticky posts
                    $sticky_posts = [];
                    $non_sticky_posts = [];
    
                    foreach ( $all_posts as $post ) {
                        if ( is_sticky( $post->ID ) ) {
    
                            $sticky_posts[] = $post;
                        } else {
                            $non_sticky_posts[] = $post;
                        }
                    }
                    // Sort the non-sticky posts by date (most recent first)
                    usort( $non_sticky_posts, function( $a, $b ) {
                        return strtotime( $b->post_date ) - strtotime( $a->post_date );
                    });
    
                    // Merge sticky posts and non-sticky posts
                    $all_posts = array_merge( $sticky_posts, $non_sticky_posts );
    ...
    }
    • This reply was modified 8 months, 1 week ago by Leo.Lin.
    Plugin Support Barn2 Plugin Support

    (@barn2pluginsupport)

    Hi, @bi1012037.

    Thank you for sharing the code solution. I’ll inform our development team about this, and we’ll follow up with any updates.

    If you have any questions, feel free to ask.

    Best regards,
    Adrian

    Plugin Support Barn2 Plugin Support

    (@barn2pluginsupport)

    Hi, @bi1012037.

    Thank you for waiting.

    Our development team has confirmed that this is a feature we haven’t implemented yet.

    While we don’t have any immediate plans to implement this, a few other customers have previously requested this feature and we’re tracking the amount of demand to help us decide whether to prioritize it in the future. 

    I have added a ‘vote’ to our feature request list.

    Thank you once again for sharing your code solution. If you have any further questions, feel free to start a new topic.

    Best regards,
    Adrian

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The functionality of sticky posts is not working.’ is closed to new replies.