WordPress WP_Query custom order_by post_type functionality

You are right, in your current approach, WordPress does not natively support ordering by specific post types in WP_Query. However, you can still achieve what you’re looking for through a custom SQL clause. By using the posts_clauses filter, you can modify the SQL query before it’s executed. Please note that using custom SQL queries should … Read more

Query multiple post types – Order by type and post title title

Yes it is, and to also sort by the post title, you would just need to add , {$wpdb->posts}.post_title <ASC or DESC> after the FIELD(), like so which results in a clause that looks like ORDER BY FIELD(wp_posts.post_type, <types>), wp_posts.post_title ASC: // Replace this: return $orderby = “FIELD( {$wpdb->posts}.post_type,” . $post_type__in_string . ‘ )’; // … Read more

Showing all posts of the current custom taxonomy on archive page

I have finally found a solution and for anyone interested, here is the working code : <?php // The Query if (is_tax() || is_category() || is_tag() ){ $qobj = $wp_query->get_queried_object(); // concatenate the query $args = array( ‘post_type’ => ‘houses’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => … Read more

How to `’orderby’ => ‘meta_value_num’` in a series of orderby parameters

The documentation for WP_Query indicates that ordering by meta value is limited to one meta key and requires the meta_key parameter (untested): $results = new WP_Query( array( ‘meta_key’ => ‘wpcf_catalogue_number’, ‘orderby’ => array( ‘meta_value_num’ => ‘ASC’, ), ) ); If you want additional sorting, you’ll need to sort the result ($results->posts) using PHP (untested): $sort__formats … Read more

WP_Query to find any published post with ID greater than given ID

If the date query doesn’t work because of modified post dates (e.g. if the posts’ timeline is no longer linear), here’s a posts_where filter’s suggestion (untested): add_filter( ‘posts_where’, function( $where, $query ) use ( &$wbdb ) { $id = $query->get( ‘_id__gt’ ); if( is_int( $id ) && $id > 0 ) { $where .= $wpdb->prepare( … Read more

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