Include posts with a specific custom taxonomy term in author page
Include posts with a specific custom taxonomy term in author page
Include posts with a specific custom taxonomy term in author page
WP_query with ajax filter not working with input fields
functions with get_post_meta
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
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
The problem is that you’re trying to do your work in a stand alone PHP, this will always be fragile, and it poses a security risk! Use a Cron Job Instead This will trigger your code to run hourly: add_action( ‘init’, function() { // If the cron job hasn’t been scheduled if ( ! wp_next_scheduled … Read more
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
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
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
I believe you could use NOT IN for the operator to achieve this along with switching some of the relations from ORs to ANDs. array ( ‘taxonomy’ => ‘plant_category’, ‘field’ => ‘name’, ‘terms’ => ‘Popular (home)’, ‘operator’ => ‘NOT IN’, ),