Custom Query With Multiple Meta Key Value

Try this: <?php $querydetails = ” SELECT wposts.* FROM $wpdb->posts wposts INNER JOIN ( SELECT post_id FROM $wpdb->postmeta wpostmeta WHERE ( ( wpostmeta.meta_key = ‘type’ AND wpostmeta.meta_value LIKE ‘%Collection1%’ ) OR ( wpostmeta.meta_key = ‘type’AND wpostmeta.meta_value LIKE ‘%Collection2%’ ) OR ( wpostmeta.meta_key = ‘type’AND wpostmeta.meta_value LIKE ‘%Collection3%’ ) OR ( wpostmeta.meta_key = ‘type’AND wpostmeta.meta_value LIKE … Read more

Sort posts by post views and consider meta key

The SQL looks correct. (You can substitute new WP_Query for get_posts and echo $my_posts->requests to see it.) So I am going to guess that the sticky posts are making it look as though the sorting doesn’t work. Add ‘ignore_sticky_posts’ => true to your arguments.

Sorting: custom query with orderby meta_value_num THEN by title

This is very crude but should sort your posts by year (meta_value) and then by title. It does depend on how the query is setup so it will only work with the query below or with similar ones. function alter_order_wpse_103181($order,$qry) { remove_filter(‘posts_orderby’,’alter_order’,1,2); $order = explode(‘,’,$order); $order = implode( ‘ ASC,’,$order); return $order; } add_filter(‘posts_orderby’,’alter_order_wpse_103181′,1,2); $q … Read more

Get foreach for meta_query value

Don’t implode $artistNames. The value meta_query argument will take an array if you use any of several compare arguments. You need IN, I believe. value (string|array) – Custom field value. It can be an array only when compare is ‘IN’, ‘NOT IN’, ‘BETWEEN’, or ‘NOT BETWEEN’…. http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters Assuming that $artistNames is an array of ids … Read more

Which Meta Query Compare Method Should I use?

There is no reason that the meta query should not work. The database column is varchar so your number is going to be treated as a string. I tested as best I can without having your database and the testing seems to confirm that. I think you are going to get a lot of spurious … Read more

Multiple Queries with meta_query

You could try this which is mostly code clean up but may solve your problem. I removed the relation from meta_query as it’s only needed if you have multiple meta keys in your query, which you don’t. I’ve also replaced the rewind_posts() with wp_reset_postdata() and finally, you were ending your IF statements earlier than your … Read more

The sorting of posts by a meta_query with two keys fails while separated as single queries it works

You can only sort on 1 meta value. A few posts (including this SE answer) suggest adding a filter to change the order. Add a function to your theme’s function.php file that will replace the sort order: function change_sort_order( $orderby ) { return str_replace(‘wp_posts.post_date’, ‘mt2.meta_value, mt1.meta_value’, $orderby); } Then use it where you want. Make … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)