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.

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

Querying by meta key and value

You can make use of REGEXP operator in META_COMPARE. For example: $meta_array[] = array( ‘key’ => ‘_item_allowed_companies’, ‘value’ => $allowed_company, ‘compare’ => ‘REGEXP’ ); $args = array( ‘post_type’ => ‘item’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => $posts_per_page, ‘paged’ => $paged, ‘meta_query’ => $meta_array ); References: WP_Query Custom Field parameters Trac ticket #18736

Display Users from two roles in one list

Since the roles for a user are stored in (dbprefix)_capabilities, I’d try grabbing the database prefix and then using it to grab people with the right capabilities (caps are in a serialized array): global $wpdb; $prefix = $wpdb->prefix; $meta_name = “{$prefix}capabilities”; ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => “{$meta_name}” ‘value’ => ‘program_manager’, ‘compare’ … Read more

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