You’ll need a second tax query for posts not in the child categories of the given category. To do that you’ll need to get the IDs of the children. This is possible with get_term_children()
:
$args = [
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $post_number + 1,
'paged' => ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1,
'tax_query' => [
[
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $category_id,
'include_children' => false
],
[
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => get_term_children( $category_id, $taxonomy ),
'operator' => 'NOT IN'
],
],
];
Related Posts:
- Return only Count from a wp_query request?
- WP_Query: Exclude hidden products from WooCommerce product list
- Conditional arguments for WP_Query and tax_query depending on if $somevar has a value
- query to find “parent” posts of CPT A while filtering “child” posts of CPT B
- Get Recent Posts by Date in Multisite
- Sticky Posts & Posts Per Page [closed]
- next_posts_link not working for loop called with ajax
- author.php with ACF and CPTs
- Identify which loop you are hooking into; primary or secondary?
- WP Query: How to get posts from a specific author OR posts with a specific meta value
- Pagination shows 404 after a certain number of pages
- Get_post() with meta_key when compare is a date
- Can I specify post__in for one particular post type in the query?
- Match two posts in categories
- tax_query in WP_Query problem
- Display posts from Last 24 hours and order them based on most views
- Query with pre_get_posts to get pagination
- Pagination is not working using WP_Query
- view queries made?
- Filter and list posts of a custom taxonomy
- Exclude first 5 posts of specific categories in the main loop
- How to show recent and upcoming birthdays using meta_query
- How to show min 1 post from specific categories/tax WP_Query?
- Posts loop with pagination on a single post page
- WP_Query & AJAX
- How WordPress attaches its Featured Images with posts?
- Tell wordpress to show a single page instead of an archive
- Have functions work outside the loop with 404 override
- how to merge a WPQuery array with a PHP array and use the Loop to Output the result
- Orderby ASC changes to DESC in WP_Query
- Iterating through $wpdb query without using get_results for large query results
- How to get only return parts of WP_Query result for performance?
- how to make members list directory through wordpress post custom meta key.
- Add capabilities via plugin for another plugin
- Two loops on archive page
- How to order posts by title after they have already been sorted by category
- Meta Query relation “AND” then set array accordingly
- How to query custom post types with mixed AND & OR statements for custom fields
- Custom post type archive pagination query issue
- Query with meta_query and tax_query together not working properly
- Adding a tax_query to a WP_Query Object
- wp_query search not taking keywords with together for multiple words
- Adding a html class based on post count
- meta_query fails to compare on values containing apostrophes
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- How to Display Shortcode in the correct location, currently displaying before content after Page Title?
- Filtering posts by archive showing all years
- Apply filters to main query instead of creating new one?
- WP_Query posts_per_page strange caching
- wp_query show all values
- Why having more than 10 clauses in WP_Query results in some outputs being dropped?
- mysql query order by
- add_query_arg to compare and display events from a certain date
- WordPress dynamic AJAX query
- Custom Taxonomy Breaks Pages
- Using rewind_posts for displaying multiple categories
- Query to get last posts from authors of blog
- WP_QUERY tax_query not working
- How to get latest post excerpt from a specific category?
- Get all content on a “single page” site depending on language
- WP_Query not returning correct result with meta_query parameter
- Order post by modified date
- Custom query to retrieve oldest post and retrieve others with date interval
- Custom order revolution sliders post base slides as inserted in Specific Posts List field
- How to display Woocommerce products list by tag
- Display the search results like the original pages
- Order 2 meta_queries differently in WP_Query?
- Unable to reset post data in wordpress custom query
- Check the product in the cart from which category is and show message
- How to filter on placeholder image
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- WP query for two post types how to order newest to oldest with two different meta fields?
- Get posts with any value in attribute
- WP_Query & shortcode : Return 3 articles from a category WordPress
- how to get dynamic data on wordpress from codeigniter?
- WP_Query doesn’t works inside loop
- Pagination in WP_Query?
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- WordPress Prevent 404 on missing custom post
- Custom query to order by multiple taxonomies
- How to add archives (with pagination) to page template?
- Custom WP_Query with SQL directives for getting posts by authors and terms
- No content found on page 2 of pagination with 1 post per page
- pre_get_posts redirecting
- Order by meta values
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- Different sql queries count indicator on the main page [closed]
- Shortcode does not display pagination [duplicate]
- Paginate wp_query while utilizing post__not_in
- Get next post when using pagination with WP_Query?
- WP_Query and DES sort for Custom Taxonomy based upon a meta field?
- Help with showing text when something is entered in my search bar
- Get Related Posts by Tag if Tag is Empty Get Posts by Category
- orderby and order filter in get_posts or WP_query function in wordpress not working
- How to order “top rated” results by date and meta key?
- 1500+ duplicate queries via get_option function (query monitor)
- Add custom argument to WP_Query and modify SQL where clause
- How does Show Posts based on a keyword search work in WP_Query
- WordPress Ajax search filter on dropdown select
- after refresh the id that shows correct in first time click, changes to 1