Force new posts to the top of query loop
Here’s a suggestion using posts_orderby filter and CASE, UNIX_TIMESTAMP and DATEDIFF (that outputs number of days) from MySQL for conditional SQL ordering: add_filter( ‘posts_orderby’, function( $orderby, $q ) use (&$wpdb) { if( ! $q->is_main_query() ) { return $orderby; } return $wpdb->prepare( ‘CASE WHEN DATEDIFF( %i.post_date, NOW() ) <= 14 THEN -UNIX_TIMESTAMP( %i.post_date ) ELSE %i.post_title … Read more