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

How do I show related posts from categories instead of tags?

In the function wp_get_post_terms() you can select the taxonomy. the default is post_tag you can change it to category. And in the WP_Query args you need to change the tag__in to category__in. // get the categories $categories = wp_get_post_terms($post->ID, ‘category’); if ($categories) { $categories_ids = array(); foreach($categories as $individual_cat) $categories_ids[] = $individual_cat->term_id; $args=array( ‘category__in’ => … Read more

Paginate_Links page 2 doesn’t work

I believe the mistake is using get_query_var( ‘paged’ ): this comes from the main query, not from your custom query. Try this (untested): $current_page = 1; if ( isset( $_GET[‘page’] ) ) { $current_page = absint( $_GET[‘page’] ); } And then replace uses of get_query_var( ‘paged’ ) with $current_page.

WP Query order posts not working

To sort by title in ascending order (alphabetical order), you can use orderby => title and order => ASC: $args = array( ‘post_type’ => ‘marketing_en’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘custom_post_type’, ‘field’ => ‘slug’, ‘terms’ => array(ICL_LANGUAGE_CODE == ‘ar’ ? ‘tool-ar’ : ‘tool’), ), ), ); $loop = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)