Wp Query custom search by meta query

I did it this way: $name = explode(‘ ‘, $name); foreach($name as $string) { $args[‘meta_query’][] = array( ‘key’ => ‘name’, ‘value’ => $string, ‘compare’ => ‘LIKE’ ); } Which works good, but I’m not sure if that’s the best solution.

WP_Query with meta_query no results

Your code looks correct. Have you checked your stored meta data to confirm the value stored is 1? Also, have you tried comparing to a string value, eg ‘1’ instead of 1? Just a stab in the dark, but worth a shot. Assuming your stored values are correct, and seeing as the values can only … Read more

Query custom field with date

According to the relevant article on the WordPress Codex, you should be able to add a type argument to the meta array. Resulting in something like this: $meta_query = array( array( ‘key’ => ‘date-available’, ‘value’ => date(“m/d/Y”), ‘compare’ => ‘<‘, ‘type’ => ‘DATE’ ), ); It’s worth noting, though (as Gopalakrishnan18 mentioned), MySQL expects a … Read more

How do you get Posts by multiple meta_keys and meta_values with the Rest API V2?

You can hook into the rest api query and add your args from url’s parameters The code will look something like: function query_post_by_fields($args, $request) { $url_params = $request->get_param; //Modify $args with your url params return $args; } add_filter(‘rest_post_query’, ‘query_post_by_fields’, 10, 2); Docs: https://developer.wordpress.org/reference/hooks/rest_this-post_type_query/