The functionality of sticky posts is not working.

[ad_1]

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 40 seconds ago by Leo.Lin.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer