How to make a WP REST API query with meta_query in WP4.7?
How to make a WP REST API query with meta_query in WP4.7?
How to make a WP REST API query with meta_query in WP4.7?
you can write like for this. ‘meta_query’ => array( array( ‘key’ => ‘_age_from’, ‘value’ => sanitize_text_field( $_REQUEST[‘age_from’] ), ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ), array( ‘key’ => ‘_age_to’, ‘value’ => sanitize_text_field( $_REQUEST[‘age_to’] ), ‘compare’ => ‘<=’, ‘type’ => ‘NUMERIC’ ) );
The problem is that you’re comparing 10000 and 10 000 as strings, and as such they are not the same value. So, you either need to sanitize the strings to ensure that both return an equivalent value, or you’ll need to force them to be integers, so that they’ll be evaluated as the same value. … Read more
if I were you, I would use the wp_usermeta table. it is possible to add information to this table easily: add_user_meta(NEW_USER_ID, “PARENT_USER_ID”,USER_ID,true); USER_ID: the Id of top level user, (In your case id of user A) “PARENT_USER_ID”: some key that you could search and find result based on NEW_USER_ID: The Id of sub_user true: To … Read more
WordPress 3.5 and up supports EXISTS and NOT EXISTS comparison operators. compare (string) – Operator to test. Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT IN’, ‘BETWEEN’, ‘NOT BETWEEN’, ‘EXISTS’ (only in WP >= 3.5), and ‘NOT EXISTS’ (also only in WP >= 3.5). Default value is ‘=’. http://codex.wordpress.org/Class_Reference/WP_Query … Read more
I figured it out, meta_query must be an array within an array as it is intended for advanced queries using ‘relation’. meta_query => array ( array ( //’relation’ => ‘OR’, ‘key’ => ‘audio_file’, //The field to check. ‘value’ => ”, //The value of the field. ‘compare’ => ‘!=’, //Conditional statement used on the value. ), … Read more
It is recommended to stick with WP_query for grabbing WordPress posts; but, you can build your own queries directly from the postmeta table, then iterate through the results. Depending on the query, this may be faster (Not often; WordPress works hard to make their database queries as fast as they can be). global $wpdb; $table … Read more
Custom Upcoming Events List for Events Manager Plugin
Meta queries aren’t intended for filtering which posts are returned. You can use them this way, but the database isn’t optimised for it. There are few things worse for scaling and performance than meta queries: Remote requests to other servers Modifying and rescaling images Queruing for what you don’t want ( e.g. show me all … Read more
From the Codex: Multiple custom user fields handling $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, 0 => array( ‘key’ => ‘country’, ‘value’ => ‘Israel’, ‘compare’ => ‘=’ ), 1 => array( ‘key’ => ‘age’, ‘value’ => array( 20, 30 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) ) ); Try adding the 0 … Read more