meta_query: check if number exists

I believe, more robust solution would be to allow multiple values of custom field ‘participants’. You can store like following add_post_meta($post_id,’participants’,’value1′); add_post_meta($post_id,’participants’,’value2′); add_post_meta($post_id,’participants’,’value3′); add_post_meta($post_id,’participants’,’value4′); Deletion would be like delete_post_meta($post_id,’participants’,’value1′); Query will then change to a simpler one. ‘meta_query’ => array( array( ‘key’ => ‘participants’, ‘value’ => $user_id, ‘compare’ => ‘=’, ), ) In case you … Read more

Rewrite gets completely ignored

Your rerite rule is incorrect. It should be (assuming download is name or slug of the page): add_rewrite_rule(‘^download/([^/]+)/?$’, ‘index.php?pagename=download&file=$matches[1]’, ‘top’); Also, you need to declare the file query var. A sample and working code: function createRewriteRules() { add_rewrite_tag(‘%file%’, ‘([^&]+)’); add_rewrite_rule(‘^download/([^/]+)/?$’, ‘index.php?pagename=download&file=$matches[1]’, ‘top’); } add_action(‘init’, ‘createRewriteRules’); Note: Don’t forget to flush rewrite rules after adding new … Read more

Advanced WP_Query with meta_query, orderby?

You should really read the documentation on meta_query‘s Here is what is allowed in a meta_query key (string) – Custom field key. value (string|array) – Custom field value. It can be an array only when compare is ‘IN’, ‘NOT IN’, ‘BETWEEN’, or ‘NOT BETWEEN’. You don’t have to specify a value when using the ‘EXISTS’ … Read more

Display post from a date range from custom field

The magic parameter ist described at WP_Query under: Custom Field Parameters You need to add a meta_query array to your $args where you define your range. In your case the code could look like this: $range = array( ‘2015-05-01’, ‘2015-05-31’, ); $args = array( ‘post_type’ => ‘score_post_type’, ‘posts_per_page’ => 5, ‘meta_key’ => ‘score_time’, ‘orderby’ => … Read more

WP_Query posts with comments only

If you’d like to change the SQL query for a WP_Query, you’re going to need to use the posts_join filter, or in your case, it’s easier to go for a simple posts_where: function my_has_comments_filter( $where ) { $where .= ‘ AND comment_count > 0 ‘; return $where; } add_filter( ‘posts_where’, ‘my_has_comments_filter’ ); $query = new … Read more

Adding a html class based on post count

If I understood this issue correctly the problem with your current code is that you are incrementing $totalPosts variable inside the while loop, so the variable gets incremented after every post thus resulting in the running order you described. To get the amount of posts returned matching the query, use $loop->found_posts (in this case) More … Read more