Using meta_query, how can i filter by a custom field and order by another one?

This seems to be a bug in WordPress. WordPress actually modifies the meta_query if you specify orderby and meta_key as query vars. Normally this modification adds the new meta_key as the first array in meta_query array and hence the orderby is applied to the first meta key specified in meta_query. But when you modify orderby, … Read more

WP Query Args – Title or Meta Value

Note that the relation part in the meta_query argument, is only used to define the relation between the sub meta queries. You can try this setup: $args = [ ‘_meta_or_title’ => $thesearch, // Our new custom argument! ‘meta_query’ => [ [ ‘key’ => ‘model_name’, ‘value’ => $thesearch, ‘compare’ => ‘like’ ] ], ]; where we … Read more

Filtering multiple custom fields with WP REST API 2

This solution works with get_items() in /lib/endpoints/class-wp-rest-posts-controller.php of the v2 WP Rest API. First, you’ll want to construct the GET arguments like you would for a new WP_Query(). The easiest way to do this is with http_build_query(). $args = array ( ‘filter’ => array ( ‘meta_query’ => array ( ‘relation’ => ‘AND’, array ( ‘key’ … Read more

How to do a meta query using REST-API in WordPress 4.7+?

You can write your own REST handler for custom queries if you want. In your case, the query can done by doing so: // Register a REST route add_action( ‘rest_api_init’, function () { //Path to meta query route register_rest_route( ‘tchernitchenko/v2’, ‘/my_meta_query/’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘custom_meta_query’ ) ); }); // Do the actual … Read more

meta_query ‘compare’ => ‘IN’ not working

There’s no easy way to search serialized values in a meta query. If the list of values isn’t crazy long, potentially you could set up multiple meta queries: ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘system_power_supply’, ‘value’ => ‘single’, ‘compare’ => ‘LIKE’, ), array( ‘key’ => ‘system_power_supply’, ‘value’ => ‘redundant’, ‘compare’ => ‘LIKE’, … Read more

How can I create a meta_query with an array as meta_field?

Feeding the query an array of possible values If the value in the database is a string and you want to feed the query several values: $args = array( ‘post_type’ => ‘news’, ‘meta_query’ => array( array( ‘key’ => ‘topics’, ‘value’ => array ( ‘sports’, ‘nonprofit’, ‘community’ ), ‘compare’ => ‘IN’ ) ) ); Searching for … Read more

Nested meta_query with multiple relation keys

The question was for WordPress 3.0, but just in case someone has the same question for a more recent version, from WordPress Codex: “Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries.” https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters So, that query should work on the current WordPress version.

meta_query with meta values as serialize arrays

No, it is not possible, and could even be dangerous. Serialised data is an attack vector, and a major performance issue. I strongly recommend you unserialise your data and modify your save routine. Something similar to this should convert your data to the new format: $args = array( ‘post_type’ => ‘my-post-type’, ‘meta_key’ => ‘_coordinates’, ‘posts_per_page’ … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş