I don’t know how the structure of $cat_not_in
looks like but make sure that that variable is not an array. If $cat_not_in
is an array then you could try
if ($cat_not_in) {
$args['category__not_in'] = $cat_not_in;
}
if ($tag_not_in) {
$args['tag__not_in'] = $tag_not_in;
}
Also see WP Codex – WP_Query it allows for category exclusion by prefixing the category ID with a - (minus)
. Worth a try too. SO if your building your $cat_not_in
array you could just prefix the IDs with -
and then
if ($cat_not_in) {
$args['cat'] = $cat_not_in;
}
Another approach completely might be to get a list of all category IDs into a $cat_get
array and then iterate through the $cat_not_in
array or string and pop the IDs you don’t want off the $cat_get
array then you can use the same code as above like this
if ($cat_not_in) {
$args['cat'] = $cat_get;
}
Related Posts:
- How to add product in woocommerce with php code [closed]
- What’s the best way to use the Featured Image for responsive web design?
- Uploading media with the REST API
- How to correctly submit a search form and display the result in an independent page
- Show the most popular post per week
- Add a class to links in the visual editor (how to get old dialog back)
- Creating custom Woocommerce attribute taxonomies from a plugin
- What is the most efficient way to search users by their display name?
- Passing JSON data from WP Query into AJAX causing NULL errors
- How to redirect users to custom lostpassword page?
- Using Echo in ShortCode – Stuck
- Get used terms by an author as array of strings
- Can I write ‘RewriteCond’ using ‘functions.php’?
- Multiple do_shortcode($content) within one shortcode
- Index showing source code
- StudioPress: add meta tag to every page [closed]
- Overriding a theme redux file in child theme
- Validate a users email address when using gmail to register
- Advanced Custom Fields Image Field returning ID instead of URL [closed]
- selected menu item
- How to show only a certain part of the entry title?
- Programmatically add and remove woocommerce product category
- allow subscribers to see private posts without plug in
- Get image’s size name from it’s dimension
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Overriding WP login credentials
- If Query In Sidebar
- Unreadable pagination
- Is there any risk setting WordPress file permissions and FS method to ‘direct’ on localhost?
- remove wp floating submenu in wp dashboard
- wp_enqueue_scripts leads to error
- Add a product to checkout via form
- My page.php shows the index.php
- Posting and image insertion problems after EasyApache4 and PHP 7 upgrade
- Can you use a WordPress front-end only and have rest of pages as pure PHP
- Security: blocking direct access of php files
- Woocommerce Show Single Product on Homepage
- Workaround for: PHP syntax error, unexpected T_STRING in load.php on line 1104 (when installing)
- Archives shortcode displaying above widget title
- Syntax error when I try to insert my loop into an unordered list? [closed]
- What exactly do this function declared into functions.php file of a WP theme?
- Display Data in Table from External Database in WP using Shortcodes
- How to check if a Customizer setting is set?
- How to overwrite orderby with add_query_var
- persist a variable set in header.php all the way down to footer.php
- Remove item in Checkout
- How to Update post_modified of all wordpress post
- how to Update 15k products on plugin activation with meta_option
- How to add a rewrite endpoint to unattached media?
- get_header_image() causes “Prioritize visible content” issue in Page Speed Insights
- WordPress cron is running with previously set time intervals and not the updated one
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Create Div Wrapper On 3rd Iteration Or When Query Loop Items Run Out
- Good RSS Feed Parser to use on php file?
- Client cant see the Updated dynamic content
- Post ID wrong in Functions.php
- Obfuscate links (for SEO purpose) [closed]
- Sortable custom product taxonomy terms via drag and drop
- get value from get_post_meta then reuse it in another get_post_meta
- Using PHP Code Snippets to query a database, $dbconnection->get_results is outputting nothing
- How to assign page id with array in page_scheduled_event
- How to remove Login from in my account page
- Header is not displaying on certain pages of wordpress theme [closed]
- Retrieve the whole widget sidebar and pass it inside an html
- Include custom fields in search
- How to access specific product id on other pages/posts?
- Intermittent 503 Service Unavailable Error
- Adding Custom css file in the wp-uploads directory with custom php functions
- Form from within a page
- How can I edit a php custom page template to work in other themes?
- ACF – Get ID of relationship field in flexible content
- Return newly created category by code
- Pulling Products from an API
- Automatically delete posts one by one depending on published time
- Hook into all password resets in WordPress and get password before hashing?
- Following/Followers Users list Using Ajax Pagination inside Author Profile
- WordPress select query issue
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- Dropdown menu on custom menu
- Pagination in WP Queries
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- Display product_brand with get_the_terms function
- WordPress error on my website
- If Elseif Query
- Querying multiple meta_keys in WordPress SQL query
- Enabling XSendFile causes 404 for images on WordPress Multisite / Network
- How to add feature image url in my template file and content as well?
- Cannot Upload Custom Header Image into WordPress Dashboard
- Add comma between variables [closed]
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- How can I list only Subcategories in Woocommerce
- echo vs output variable [closed]
- Display Post Titles on top of the_post_thumbnail()
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- Contact form with dynamic dropdown and filter
- Critical Error customiser
- how to create twitter card without plugin in wordpress website?
- How to use phpspreadsheet reader with $wpdb
- How to modify default tags in wp_head()