Array as ‘key’ in WP_Query
In addition to the suggestion by @AhmedMahdi to solve your problem, here’s the narrower answer to your question: Nope, key cannot be an array. As you can see in the specs of WP_Meta_Query key must be a string.
In addition to the suggestion by @AhmedMahdi to solve your problem, here’s the narrower answer to your question: Nope, key cannot be an array. As you can see in the specs of WP_Meta_Query key must be a string.
You can pass your meta query into query_posts or (the preferable) WP_Query in 2 ways: An array using the array keys meta_key, meta_value, meta_type and meta_compare An array of arrays using the array keys key, value, type and compare In your question, you were trying to use a mix of the two, and that’s why … Read more
On top of my head this should be something like: ‘meta_query’ => [ ‘key’ => ‘_EventEndDate’, ‘value’ => [ $start, $end ], ‘compare’ => ‘BETWEEN’, ‘type’ => ‘DATETIME’ ] You would need to calculate boundaries yourself before passing to the query in this case. See Custom Field Parameters in Codex for full documentation on parameters … Read more
Post meta data was never designed to be used efficiently in queries. Using it with LIKE based matching will only make it more horrible. You need to rethink your DB. For example use taxonomy terms to indicate which social network is associated with a post.
Neither option are the correct option for your use case Your question is barking up the wrong tree, because you neglected to mention that you intend to search for these posts based on the values the meta holds. If you’re displaying a post, you can use either method, though the first is cleaner/simpler to handle … Read more
The documentation for this is contradictory, but I believe wp_sitemeta is meant to only store information for sites in the wp_sites table, which only stores the main site in a network. It would make more sense to store each site’s template_color in their individual wp_[BLOGID]_options tables. However, keeping the data as-is, you may be able … Read more
The value passed to reset() is passed by reference, which means technically it modifies the original variable that’s passed to it. For this to work you need to pass a variable, not a function that returns a value. reset() rewinds array’s internal pointer to the first element and returns the value of the first array … Read more
Tax query is formed wrong. It also array of arrays(queries) get_posts([ ‘meta_query’ => [ [ ‘key’ => ‘country’, ‘value’ => ‘Japan’, ‘compare’ => ‘LIKE’ ] ], ‘tax_query’ => [ [ ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => [‘kids’] ] ] ]); the array should look like this: Array ( [meta_query] => Array ( [relation] … Read more
The main issue in your code is this part: $query->set(‘orderby’,’meta_value_date’); whereby you should use meta_value and not meta_value_date. (There is meta_value_num, but that’s not suitable for used with sorting by dates.) Then make sure the meta_type is set to DATE (which yes, you already done it correctly), and use the right date format — 10132020 … Read more
If I understand it correctly.. What you’re looking for can be achieved using the CASE statement in MySQL, where you would use the following in the ORDER BY clause: # group the quantity meta into two groups CASE # group one – all quantities that are 1 or more; we flag them as “1” WHEN … Read more