If you use category__in
and category__not_in
instead, it will only pull the posts that are in that category, not the subcategories as well. For your code, this would look something like this:
$args = array(
'category__in' => $cat,
'category__not_in' => $catHidden
);
Note: this will only exclude posts that are directly in the category as well. If you want to exclude posts in that category and the subcategories of it, use cat
with the negative syntax.
Also, if you need more powerful querying, this can be found with the tax_query
parameter, which will allow you to set an include_children
parameter for each taxonomy and term you are querying for.
Related Posts:
- exclude category from get_posts?
- Get id of category from drop down menu
- Show post only if match all categories
- Show recent posts from one category on a non-WP site
- get_posts and multiple categories
- Trying to only display 1 category using get_posts
- Get link which associated with a specific category and tag
- Get posts from 2 different categories
- Get posts from specific taxonomy term
- List all posts in a category with query_post() function
- Hooking to walker_nav_menu_start_el to insert list of subpages
- get_posts ignoring ‘category’ and displaying all posts
- How to Link to Most Recent Custom Post of Same Term
- get_posts() from parent category only using a shortcode
- Exclude parent category when getting category posts by slug
- Exclude categories from homepage not longer working
- Showing posts from 2 categories only on category.php
- get all categories’ latest post in one query
- Load the last post of a category
- get_the_category return empty inside loop
- Get posts base on category ratio of more then two categories
- Media Library Category Exclude Tree
- not empty categories don’t show in menu [closed]
- how to call the category of the post
- How to create a custom loop ordered by Categories on a Page Template?
- How to change category id on get_posts array
- get posts from 2 categories. (2 posts)
- how to ask if in two categorys inside if
- How to create a custom sort for WordPress categories
- Hook when category is added to post
- get_categories for custom post type with a specific custom taxonomy attached
- How to add the category ID to admin page
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Category Archive
- Exclude categories from Loop, queries, widgets, post navigation
- Sticky posts on home page, search, tag and archives without plugin
- WordPress 1 domain multiple blogs
- Show Post from parent category (custom taxonomy) ONLY!
- One WordPress Install, Two Categories. Each Category Gets a Domain
- Name of last category level for a post
- How to add style to category link?
- Filtering Children of the “uncategorized” Category out of the Loop?
- Update wordpress post terms programatically
- Filtering search results
- Display products for a category, sorted by post_excerpt
- “NOT ONLY IN” taxonomy query operator?
- How do you bulk remove a category from posts?
- How to remove the “+Add Category” button from the Category metabox?
- Display the featured image from the last post
- conditional for sub category on archive page
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- How can I create a Category Index page that lists all categories?
- Changing permalink from /postname/ to category/postname/
- Assign automatically and manually modify category
- Scheduling update post daily
- Retrieving category’s color with get_term_meta
- Assign category from custom field on post creation and update
- Sticky posts not working when a specific category is set
- previous/next_post_link in the same sub-category?
- Custom category URL rewriting
- Get Number of total Parent Categories for Custom Taxonomy
- How to change how many list item show in category generated by file edit-tags.php
- How do I display something on a particular category page?
- Exclude category from related post
- Post belonging to many categories
- how do I use the walker class to display categories in their correct heirarchy?
- WP 4.7 in_category change?
- display category list year wise in wordpress
- Display subcategories in dropdown
- Illegal string offset ‘taxonomy’ in
- Are term_taxonomy_id and term_id the same? [duplicate]
- Display all sub category but one
- Filter Category Loop Dynamically
- SQL query to get posts from multiple categories but not in a category
- Can each user have only access to a private area (his own categories and posts)?
- WP Category Meta plugin fix? [closed]
- WP SQL Categories Export and Import
- Why are my newly added categories not showing up when creating a post?
- WordPress Default Category and Custom Taxonomy Selected Attribute not Working After Searched in wp_dropdown_categories Array
- How to add the .html extension to the category?
- Add filter for specific category only
- How to exclude a category returned by get_categories from function.php?
- Getting a sub category based on a category name
- How to display only sticky posts on category pages?
- Conditional statement: if is_category, append at the end of page
- How to Manage and link certain custom taxonomy?
- Store All Post Categories In Array
- Help with SQL query, how to add taxonomie terms with value stored in options?
- /blog/ permalink prefix causes category pages to 404
- How to create an array with category ids order by the one that has the most recent post
- Conditional statements based on custom meta value in category archives
- Placement of categories
- Categories Going to different Blog Pages?
- Paginate WordPress Category Pages
- Get a list of post titles and links from yootheme master theme
- How to structure Multisite sites into categories?
- Template files not working for archives and categories
- Excluding cateory not working on my site. how to solve this? [closed]
- Get all first images of posts in same category
- What defines a post as portfolio page content?
- How to remove the category from the url only for a specific category of articles on wordpress