How can I prevent posts with no title showing up in my query?

Please find below a quick solution to your problem first query for all empty titles place the result in an array query again for post__not_in see below sample code $query = new WP_Query(‘post_title=\’\”); $a_empty_titles = array(); while($query->have_posts()){ $query->the_post(); array_push( $a_empty_titles ,$query->post->ID); } wp_reset_postdata(); wp_reset_query(); echo count($a_empty_titles); $query = new WP_Query( array( ‘post__not_in’ => $a_empty_titles ) … Read more

sort and display posts by custom field (wp-query and the loop))

I believe the meta_query part should be a nested array, so your query should be like this: $query = new WP_Query( ‘post_type’ => ‘post’, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘ENDS’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array ( ‘key’ => ‘ENDS’, ‘value’ => date(‘Y-m-d H:i:s’), // now ‘compare’ => ‘>=’, ‘type’ => … Read more

get_posts() and global variables

get_posts doesn’t modify global variables & is safe to use anywhere but setup_postdata does modify the global variables. Use the function wp_reset_postdata() just after the foreach loop. It reverses the changes made by setup_postdata. The thing it does is basically same as you did in your example, you just won’t need to worry about the … Read more

WP_Query parameter conflict

Is your post type non-hierarchical like a post – or hierarchical like a page? It will determine which slug parameter you should be using in WP_Query: name (string) – non-hierarchical (post) slug. pagename (string) – hierarchical (page) slug. Also, the tax_query should have the operator parameter. Possible values are ‘IN’, ‘NOT IN’, ‘AND’. You should … Read more

Can’t understand why sometimes a [caption] field appears

The part shows up because one of your authors/editors added a caption to the image when it was inserted into the post. You will have this problem not only with captions but with any other shortcodes that your authors/editors use. And you should be aware that WordPress includes several in its Core but various plugins … Read more

WP Query – posts only by specific user

If all you need to do is add that extra parameter, just concatenate it on to the end of $args. (As a side note: I recommend using an array for args instead of the query string method as I find it much more readable.) <?php …. $args=”&posts_per_page=”.$numreviews.’_reviews&order=DESC&orderby=’.$feedsort.$metakey.’&author=123′; ….