meta query based on month regardless of year

While the regexp solution will function, it quickly gets slower as the number of users increases. This is because the database cannot perform optimisation and indexing tricks, and forces a full table scan. The more users, and the more meta, the greater the cost of the query. At a minimum it requires caching to avoid … Read more

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

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

meta_query with multiple key

key in a meta query needs to be a string, you can’t pass multiple keys to a single meta query. You’ll need add a query for each key: $filter = array( ‘post_type’ => ‘request’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => $key1, ‘value’ => $search_value, ‘compare’ => … Read more

wordpress Meta_query between numbers range (not working)

you can use meta query operators like below query. See docs for meta_query parameters here $range = $_GET[‘range’]; // assuming you get the range from query string parameter which 11-19 $range_array = explode(‘-‘,$range); $args = array( ‘post_type’ => ‘YOUR-POST-TYPE’, ‘meta_query’ => array( array( ‘key’ => ‘sizes_avaliable’, ‘value’ => $range_array, ‘compare’ => ‘BETWEEN’ ), ) ); … Read more

Get a single post ID based on an exact match of 1 or more meta values

If you want to match them all, you have to add ‘relation’ => ‘AND’ and check for each value separately: $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘_some_meta_key’, ‘value’ => 1, ‘compare’ => ‘=’ ), array( ‘key’ => ‘_some_meta_key’, ‘value’ => 2, ‘compare’ => ‘=’ ), array( … Read more

Meta query date column add [x] days to validate

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

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