Order by meta value

Use meta_value_num with orderby instead of meta_value. meta_value is used to order alphabetically. meta_value_num used to order numerically. For more information, check this: Codex get_posts And this for detailed information: Codex WP_Query

I would like to have add_post_meta to return the ID instead of true or false

According to the Codex, using add_post_meta() you can’t. That function is supposed to return either true or false. However, that function is a thin wrapper around add_metadata()… 1726 function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) { 1727 // make sure meta is added to the post, not a revision 1728 if ( $the_post = wp_is_post_revision($post_id) … Read more

WP_query – Filter by tax_query and meta_query using multiple select

My initial code did not provide default WP_query argument parameters if either Select option was not set – the empty Parameter would filter everything out. To the best of my ability, I applied default parameter values from the initial Post and Terms queries and now the select filter is working. I would be pleased to … Read more

Meta query for comparing two dates

EDIT start and end date is following the date format. But you are using NUMERIC type casting in meta query. You need to use DATE type like array( ‘key’ => ‘user_registered’, ‘value’ => $start_date, ‘compare’ => ‘>’, ‘type’ => ‘DATE’ ), array( ‘key’ => ‘user_registered’, ‘value’ => $end_date, ‘compare’ => ‘<=’, ‘type’ => ‘DATE’ ) … Read more

Searching for meta_key returns 0 posts

To narrow down the possible causes I’d strongly recommend using a debugging plugin on your development server, like Query Monitor, so you can see the SQL being generated by your query. Alternatively check the request property of your $wp_query object. It’s always possible, if you only recently installed the plugin, that there aren’t any posts … Read more

Orderby doesn’t work like expected on custom query

First of all, never ever use query_posts. It breaks the main function and all plugins and functions relying on the main query object. For custom queries, use WP_Query or get_posts if aren’t looking to paginate the query As for the following line ‘orderby’ => ‘rr_recommends_count’, I can tell you that rr_recommends_count is an invalid value … Read more

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