How do I get posts that have a thumbnail in WP_Query?

You should be able to call posts with a featured image with the following code: $thumbs = array( ‘posts_per_page’ => 5, ‘meta_query’ => array(array(‘key’ => ‘_thumbnail_id’)) ); $query = new WP_Query($thumbs); The code checks each post for the custom field _thumbnail_id, which is where the thumbnail image is stored.

Wp_redirect and sending variables

I’m afraid that you can’t do it this way. wp_redirect is a fancy way to send header Location and the second argument of this function is request status, and not custom variable. (404, 301, 302, and so on). You can send some variables as get parameters. So you can do something like this: if ( … Read more

why ignore_sticky_posts in sticky post query

We all know that ignore_sticky_posts is used to exclude sticky post from your custom query. – No, this assumption is wrong. What ignore_sticky_posts means: Even though in natural English, ignore_sticky_posts sounds like WordPress should ignore all sticky posts from the query, in reality that is not what WordPress does. Instead, you should read ‘ignore_sticky_posts’ => … Read more

Posts with at least 3 tags of a list of tags

The answer below is simplified, and could be extended to check if any posts have 3 matching tags before outputting the list. Using one query and assuming you have at least one post with 3 matching tags: //List of tag slugs $tags = array(‘foo’, ‘bar’, ‘chocolate’, ‘mango’, ‘hammock’, ‘leaf’); $args = array( ‘tag_slug__in’ => $tags … Read more

How to merge two queries together

A single query Thought about this a bit more and there’s a chance that you can go with a single/the main query. Or in other words: No need for two additional queries when you can work with the default one. And in case you can’t work with a default one, you won’t need more than … Read more

tech