meta_query: check if number exists

I believe, more robust solution would be to allow multiple values of custom field ‘participants’. You can store like following add_post_meta($post_id,’participants’,’value1′); add_post_meta($post_id,’participants’,’value2′); add_post_meta($post_id,’participants’,’value3′); add_post_meta($post_id,’participants’,’value4′); Deletion would be like delete_post_meta($post_id,’participants’,’value1′); Query will then change to a simpler one. ‘meta_query’ => array( array( ‘key’ => ‘participants’, ‘value’ => $user_id, ‘compare’ => ‘=’, ), ) In case you … Read more

Advanced WP_Query with meta_query, orderby?

You should really read the documentation on meta_query‘s Here is what is allowed in a meta_query key (string) – Custom field key. value (string|array) – Custom field value. It can be an array only when compare is ‘IN’, ‘NOT IN’, ‘BETWEEN’, or ‘NOT BETWEEN’. You don’t have to specify a value when using the ‘EXISTS’ … Read more

ORDER BY custom field value out of where clause

Define that a population has to be set, and make a list of allowed states as an array. Afterwards, take population into the orderby and sort it DESC. $q = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘state_clause’ => array( ‘key’ => ‘state’, ‘value’ => array( ‘Wisconsin’, ‘California’ ), //allowed values ‘compare’ => … Read more

Wp_query with 2 meta keys and array of meta values

I think you need to do something like this: <?php $args = array( ‘post_type’ => ‘shop’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘cu_status’, ‘value’ => array( ‘pending’, ‘processing’ ), ‘compare’ => ‘IN’, ), array( ‘key’ => ‘cu_date’, ‘value’ => array( ‘2016-01-12’, ‘2016-01-13’ ), ‘compare’ => ‘BETWEEN’, … Read more

WP REST API – get custom taxonomies based on terms & filter

Herewith find the below answer for my own question for the custom taxonomies based listing the categories add_action( ‘init’, ‘rest_custom_category_request’, 25); function rest_property_type_category_request(){ global $wp_taxonomies; $wp_taxonomies[‘custom_category’]->show_in_rest = true; $wp_taxonomies[‘custom_category’]->rest_base=”custom_category”; $wp_taxonomies[‘custom_category’]->rest_controller_class=”WP_REST_Terms_Controller”; } Answer for the filter with custom meta key & values add_filter(‘rest_query_vars’, ‘custom_rest_query_vars’); function custom_rest_query_vars($query_vars) { //print_r($query_vars);exit; $query_vars = array_merge( $query_vars, array(‘meta_key’, ‘meta_value’, ‘meta_compare’) ); … Read more

How to provide meta_key array to wp_query?

The WP_Query() custom field (i.e. meta) query can handle arrays for field values. You just need to add the compare key to your array: $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘post’, ‘meta_query’ => array ( array ( ‘key’ => ‘my_key’, ‘value’ => ‘target_value’, ‘compare’ => ‘IN’ ) ) ); $new_query = new WP_Query( … Read more

Custom Query Content Filtering

I assume that your posts are having make and model as a Custom Fields and you want to retrieve all those posts which are matching both the passed value for make and model Custom Fields. If that is the case then your code seems to be correct. It might be possible that there is no … Read more

Meta Query doesn’t works as espected

Mariolex, Have you tried using meta_query? I wrote something quick and untested but it may do the trick: $args = array( ‘post_type’ => ‘posts’, ‘showposts’ => ‘-1’, ‘meta_query’ => array( array( ‘key’ => ‘pickup_address’, //meta_key ‘value’ => ’43 Longview Drive, Papamoa’, //meta_value ‘compare’ => ‘LIKE’, //compare ), ), ); $query = new WP_Query( $args ); … Read more

meta_query with multiple key

key in a meta query needs to be a string, you can’t pass multiple keys to a single meta query. You’ll need add a query for each key: $filter = array( ‘post_type’ => ‘request’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => $key1, ‘value’ => $search_value, ‘compare’ => … Read more

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