You need to add a \
in front of the WP_Query
call to tell PHP that it’s in the global namespace and not the namespace of this class.
Try this: $query = new \WP_Query($args);
Related Posts:
- Use post object from first query in second query
- Use Repository Pattern in WP theme
- How do I get posts that have a thumbnail in WP_Query?
- Multiple WP_Query loops with Pagination
- WordPress get_posts function, 1300 lines long
- IP address character limit
- What is the most efficient way of querying posts based on visits and date for current day?
- Initiating WP_Query() with no args and adding them later through the query() method
- Pagination custom query
- WP_Query and name__in
- Searching user meta using WP_User_Query
- WP Query with offset breaks wp_pagenavi or any pagination
- Show list of authors with latest post NOT older than a month
- Unable to combine “search value” and “tax_query” using WP_Query
- How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts
- Filter WordPress posts by between parameter
- wordpress query in header won’t reset and corrupts other loops
- How add a custom posttype name using ACF field to a query post array
- 2 loops on page – one with orderby rand second orderby date
- Undefined WP_Query::has_posts()?
- Php Trying to get property ‘ID’ of non-object
- More than 1 Year Date Query
- Splice together 2 WP_Query objects
- How do I force WP_query to fetch fresh, non-cached results?
- WP_Query posts_per_page Only Bringing Back one post
- How to get all unique categories for posts in loop?
- Query that loads a custom type AND posts whose ids are not inside those custom types custom fields
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Get and Trim Full Post Content in WP Query
- How to Union two different conditions in one WP_Query
- Display filtered results into custom page
- WooCommerce – get product sub categories
- Transient not behaving as expected
- how can I override The Events Calendar query modifications?
- No results found from a $wpdb->get_results() query when trying to join more than one meta key query
- WP_Query post_parent parameter always returns children of current page
- WP_Delete_user link creation
- How to exclude post formats from wordpress recent posts in a tabs widget [closed]
- Query about wp_query
- wp_query sort with meta_value_num is not working
- How to pass orderby params to $wpdb->prepare()?
- how update data through ajax and jquery
- Query posts only without featured image
- WP_Query arguments relation shows AND instead of OR
- Combine results of multiple WP_Query to resemble single WP_Query
- How to use WP_Query() on single.php?
- Using WP_Query() in Magento shows error
- Can’t fetch Custom Post Type Data through Custom Query
- Loop increase in while loop not working
- Get All posts by Tag_Id not working, query seems to contain extra term_taxonomy_id
- Is this meta query problematic?
- Utilising an existing page while using the “s” query parameter
- posts archive page – closing WP_Query loop correctly [closed]
- Yoast primary category query modification
- AJAX Breaking Offset Argument In WP Query
- Excluding posts with certain value of meta_key keeping posts without that meta_key
- Pagination in html table is not working
- Filter out a meta key in the Search results page with two CPT
- Function using get_posts() with tax_query not working when called from functions.php
- Why does WP_Query have methods that return public properties of the same name
- Include one page/post into query which is already returning posts
- Search for pages with permalink
- Don’t repeat posts from children in parent taxonomy query
- WP_query paged pagination with excluded category still counts it
- meta_query with array as value with multiple arrays
- Why doesn’t my WP Meta Query return any results?
- Help with if statement inside while loop
- wp-query problem with author
- Filter for each loop when WP_Query has no posts to show
- Custom WP Query order function possible?
- How sort products by calculate value? ( custom post meta, price, option)
- wc_get_products() return empty object
- Pagination unique to a widget
- Ascending numerical sorting with non-numerical characters last
- WP_Query not returning custom post type
- How do I use $wp_query->current_post with get_template_part? I’m trying to add post classes (first/last/even/odd) to custom loops
- Why pagination is not working with tax_query param?
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Is the ‘parse_query’ filter still valid to change filtered content on admin list view?
- I removed the “wp_rm_logs” table and am constantly getting this error
- How to set selected attribute on option after filter query?
- custom search form, posts_per_page value being ignored
- Fetching $_POST from Page Template into functions.php
- Custom query with post_class filter using current_post not working
- posts_per_page not returning correct number of posts
- Inline Ajax call after term is appended with a @ or # etc. displayed in div
- Loop the posts between two dates selected using jquery datepicker
- Passing conditional arrays to WP_Query() [closed]
- Query custom post type by date field only working when two posts match the query
- Why isn’t my Meta_Query running?
- How to specify a certain amount of images queried, not all?
- wordpress sorting using array merge by price in ascending order but price with 0 must be show last
- Carousel Loop only duplicating
- Remove divs and spans from post content
- How to show featured post first, then separate loop for other posts
- error with $query->have_posts()
- Get all user with both meta_value
- How to retrieve _embed (etc) fields in get_posts custom query?
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- Is there another way to retrieve a post_id from post_meta other than a SQL query?