Query posts by searching for a string in a meta field
First of all – I assume the $search variable is being populated from $_GET (it’s not in your code). Secondly, do you need the % ? I think using LIKE with wp_query doesn’t require them.
First of all – I assume the $search variable is being populated from $_GET (it’s not in your code). Secondly, do you need the % ? I think using LIKE with wp_query doesn’t require them.
You have some errors on how meta_query array is setted for price-max and price-min. Also in your code will be an issue if no $_GET[‘beds’] are sended but $_GET[‘price-min’] and $_GET[‘price-max’] are. this because the $args[‘meta_query’] array is setted inside if($_GET[‘beds’] >= 1). Moreover your code will throw a lot of notices if the GET … Read more
The default relation is AND so you really don’t need to specify that, but I’ll show you how to do it anyway. Really, you just have an array manipulation problem. $amenities = array(‘a’,’b’,’c’); $amenities2 = array(‘d’,’e’,’f’); foreach ($amenities as $a) { $arrays[] = array( ‘key’ => ‘amenities’, ‘value’ => $a, ‘compare’ => ‘LIKE’ ); } … Read more
In both examples, you are searching between ‘max’ and ‘min’, where it should be between ‘min’ and ‘max’: array( $dist[‘max_latitude’], $dist[‘min_latitude’] ) ‘value’ => $dist[‘max_latitude’], ‘compare’ => ‘>=’); ‘value’ => $dist[‘min_latitude’], ‘compare’ => ‘<=’); Both mean: “Search for a value that ist greater than max_latitude and less than min_latitude” Another finding why my own meta_query … Read more
Short answer: You can’t do that. The query system is a simplified version, by design. It cannot do combinations of ANDs and ORs across keys like that. If you want to do that, you’ll need to write your own SQL in some manner. The meta_query is not capable of that complex of a query.
UPDATE: Sorry, apparently my solution faces the same problem when the query contains values such as ‘$599,000’ or ‘$1,149,000. so far, the only solution so far was cleaning the database imported data values to INT/UNSIGNED (even though, meta_value is saved as TEXT). However, the meta ordering by value still don’t work quite as it should. … Read more
Why don’t you use wp_query to retrieve posts. Its’s easy to include meta values in wp_query and a safe way to retrieve posts from wordpress database. use this code to switch to the desired blog id and then after retrieving posts switch back to the original blog. <?php /* for global variables, since it is … Read more
If you only have two types (directors and none directors and you allready get all of the directors you can simply use the post__not_in parameter, ex: // Get your directors just like you do now // $directors = get_posts(array( … // Then create a simple array with only the post id’s of the directors. $directors_ids … Read more
I tried with regular meta_key – meta_value pair and it works as it should… $name = get_the_title(get_the_ID()); $args = array( ‘post_type’ => ‘project’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘program’, ‘meta_value’ => $name, ); $projects_q = new WP_Query($args);
The query will by default GROUP BY the post ID, meaning that a post will only appear once in the list. You can remove that GROUP BY pretty easily with a filter: add_filter(‘posts_groupby’,’__return_empty_string’); $events = new WP_Query($args); remove_filter(‘posts_groupby’,’__return_empty_string’); That might get you what you want. It is a bit hard to tell. Without the GROUP … Read more