You need to define your arguments before you pass them to WP_Query
, not after. Also, your meta_query
should be an array of an array, not just an array
This
$query = new WP_Query($thumbs);
$thumbs = array(
'meta_query' => array('key' => '_thumbnail_id')
);
should look like this
$thumbs = array(
'meta_query' => array(
array(
'key' => '_thumbnail_id'
)
)
);
$query = new WP_Query($thumbs);
EDIT
Just a few extra notes
-
Make sure to reset postdata after a custom query. Just add
wp_reset_postdata();
before you close yourif
statement and just after closing yourwhile
statement -
I believe that a custom query might not be necessary here. If I read your question correctly, you can simply use
pre_get_posts
to alter the main query. You shouldn’t use a custom query just because you want to alter the main query
Related Posts:
- How can I check for a thumbnail in WordPress?
- Wp-query and column blocks
- How to filter on placeholder image
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- How to uniquely identify queries?
- Add the “active” class only to the first loop item in a WordPress query [closed]
- Get posts by meta data OR title
- Display Posts by modifying the where clause only for my query
- page was loaded over HTTPS, but requested an insecure image
- WP_Query: How do I sort on meta value and use LEFT JOIN?
- Pagination causes error 404 when used with front-page.php
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to search by title or tags exclusively?
- Using AJAX to return search form results
- How to get a category in a list item class
- Add custom search results to main WP search [duplicate]
- What is the difference between RELATION “AND” and “OR” in TAX_QUERY?
- Finding post content that begins with a specific character
- Query Set Order By Author
- ‘&’ causes an error in my shortcode when I list the content of the page
- SQL Query inside Widget
- meta_query works locally but not on live server
- Use ‘parse_query’ filter to show posts that from multiple criteria
- How can I pick a single post from the latest 3?
- Get posts for last working week in WP_Query
- how to link to detail page(single.php?) in a wp_loop
- WP_User_Query unable to retreive all user at once
- Meta Query Array Error 500
- getting post thumbnail within loop causes an error
- Reset postdata to custom query in nested queries
- Get pagination working for custom loops within page templates
- Complex WP SQL Query
- Hide Administrators From User List except current user (administrator)
- Custom Query num_rows returns wrong amount
- How to figure out redirection and contents in hybrid solution containing word press content and legacy code (ASP.net)
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- Most commented post showing 2 records
- How to store and receive variables in WP sessions?
- How to list posts with disabled/closed comments, with pagination?
- Category ‘pad_counts’ & ‘parent’ conflict
- how would i change post->ID to work correctly when querying pages?
- WP User Query with Custom Fields and Search Results
- Event with multiple dates, display events chronologically
- How to exclude Sticky from Recent Post?
- Display if author page is author page of current user
- WP_Query order by not working properly due to category I believe
- get_query_var always returns the default value
- Modify WP_Query using pre_get_posts but only for frontend query?
- Multiple wp_query on archive page
- WP_Query to get post on frontpage
- When listing child pages run out of memory
- Function to retrieve IDs of posts, cache results, and improve wp_query
- parse_tax_query causing Navigation Menu To Disappear
- WP_query is not returning the expected result
- the_post_thumbnail do 2 queries. How to optimize
- wp query meta value is not null
- Search.php – return number of results but cannot loop through
- Creating ‘posts page’ loop based on the page itself
- How to get pages of parent (non-recursive)?
- WP_Query and pagination AGAIN?
- Can’t get term id for category archive
- Show X taxonomies of the latest published posts
- Combine query in WP_User_Query()
- Nearby locations using Advanced custom fields, maps?
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- How to display the category dropdown auto search list when key press?
- WordPress Query custom ordering by temporary variable
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- order by post date and modified date posts both in wpquery
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- How to get_comments() ordered by date and parent?
- WPQuery loop not giving expected output
- WP Query filters active on wrong query
- Not able to fetch woocommerce variation sales products for particular category products
- Global page ID variable empty error
- WordPress tax_query ignoring relation OR
- pagination functions are not working
- Gather same custom field values in one value in a select tag with wp_query
- Wrap group of wp query posts to parent div by date/year
- Continue loop after $queryObject
- Order Posts By Youtube Views
- WP Query with sticky posts and tax_query
- Declare inline background image in functions.php
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]
- loop through custom post types with meta data
- Looking for a way to exclude frontpage and nav menu from query filter
- Using Query In Post Type Archives
- Query posts by custom fields
- Showing posts from 4 categories along with all latest posts
- Searching in specific custom post type
- WP Query Obj: Set value to be unequal | Hide media by admin
- WordPress pagination returns the same posts
- SQL query into to WP query
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- I want to place a post before all others from an ACF boleen field
- How to put posts with some taxonomy on top of others in `pre_get_posts`