WP_Query with multiple meta fields filter?

I have the following query but it is still returning results which include posts which have a meta value of ‘deal’. Any Clues on what am i missing in this $args = array( ‘post_type’ => POST_TYPE, ‘meta_key’ => ‘is_hot’, ‘meta_value’ => ‘1’, ‘meta_compare’ => ‘=’, ‘posts_per_page’ => 20, ‘no_found_rows’ => true, ‘suppress_filters’ => false, ‘meta_key’ … Read more

CPT Meta Searching

I’m developing a WP plugin which uses custom post types and meta data. What I’m trying to achieve is having the meta data searchable. Here is some code that I found which searches the meta data fine, however I can’t get it to display the search string on the CPT page. add_filter( “pre_get_posts”, “custom_search_query”); function … Read more

Order Posts by meta value AND published date

I want to order WP posts by meta key named “sort_date” and if it doesn’t exist it should use the post’s published date to order posts. Below is the code i am currently using function pre_get_posts_custom($wp_query) { if ( !is_admin() && $wp_query->is_main_query() && !is_page() ) { $meta_key = ‘sort_date’; $wp_query->set( ‘post_type’, array( ‘post’, ‘article’ ) … Read more

Meta_query with relation ‘OR’ killing server CPU

function get_nb_offres( $typeOffre ) { global $type_bien_correspondances; $args = array( ‘post_type’ => ‘annonces’, ‘meta_query’ => array( ‘relation’ => ‘OR’ ) ); foreach( $type_bien_correspondances[$typeOffre] as $typeBien ) { $args[‘meta_query’][] = array( ‘key’ => ‘type_de_bien’, ‘value’ => $typeBien ); } $annonces = new WP_Query( $args ); return $annonces->post_count; } My global $type_bien_correspondances is here : $type_bien_correspondances = … Read more