You can use the same code, you just have to find the id of your category by slug.
Yo can do this by adding :
$idObj = get_category_by_slug('category-slug');
$id = $idObj->term_id;
And then put $id
in your excluding array.
the function is documented here : wordpress documentation
Related Posts:
- exclude multiple terms using get_terms() function
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Allow authors to post only in categories they create in WordPress
- Add custom field to attachments in a specific category
- How to Populate the list of custom post type categories
- Php string not working in WordPress Functions.php [duplicate]
- Problems with function on function.php
- Use template for posts with a particular category grandparent
- Put a link to a category round a hard coded A HREF
- Check if Product is in a Specific Category in Functions.php
- Get posts with at least one category in common with current post?
- Woocommerce – remove product from category
- get current product name in functions.php
- get post based on category chosen in drop down – The ajax method
- Swapping wp_dropdown_categories function with wp_category_checklist
- What is an equivalent of single_cat_title for getting the slug of the category?
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to pick the default selected value in wordpress dropdown?
- Get page that displays all children of taxonomy parent
- Redirect to another page using contact form 7? [closed]
- Dilemma of Populating all the categories in a drop down list
- Edit the_category (); for a hierarchical display
- Displaying posts based on category
- How to get current post category details inside “loop”?
- Show all tags within a category?
- Post not populating for custom post type based on category selection
- Allow two posts (from different categories) to have the same slug
- Dropdown category field inside repeatable metabox
- Get nice name of category from slug (remove dashes of category)
- Display Visual Composer shortcode if a post belongs in specific categories
- Get parent category name when only child category is applied to a product
- How to move a post from one category to another
- Notice: Undefined variable
- Populate Posts based on category selected using AJAX that means without page refresh
- All categories options or All categories not Populating
- Exclude a category slug on pagination
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- PHP get_category() function redeclared
- WordPress using get_term to retreive slug not working as expected
- Get category id for a custom category and display it in a class
- Trying to see if page is category or single and displaying title with appropriate heading tag
- get_category only returning details for ‘uncategorized’
- Displaying categories
- How to insert the first letter in uppercase [closed]
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Exclude a category ID from the following function
- Help with get_categories code
- Is it possible to go to the next post in the same category?
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- How do I display a user’s previous orders as a select box option on a product?
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- allow subscribers to see private posts without plug in
- Replace word in “the_content” only for index.php
- How to query for pages/post depending on slug?
- How do you add customer capability after Woocommerce purchase?
- How to get specific image in media library with php
- Function set default image when image not present
- Custom location for attached images
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- WooCommerce – Reset quantity input field when variation changes
- Query all posts of a custom taxonomy term
- Get first URL from post content
- Setting custom canonical urls
- Handling Body class based on Template
- Trigger popup in a php if/else statement
- Setting a cookie upon specific URL visit
- WordPress custom slug (endpoint) and compare all links
- Get_avatar filter?
- Can’t get page content in WordPress
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Way to querry data (tags) from a wordpress database?
- How to use transient in this code for related post?
- Adding Default Settings to Theme My Login plugin
- Image as Sales Badge
- Global variable $post returning incorrect object
- how to make separate field in wordpress user_data_
- Function not working at one place
- jQuery not defined
- Displaying the Month and Year that a page was Created?
- Changing custom logo link
- Add a class to the anchor tag on HTML5 gallery
- How do you use WP slugs for PDF files / media?
- Conditional Header in wordpress
- Remove meta description on certain pages
- Creating a related post section based on similar categories
- Menu — How to add “current-menu-grand-ancestor” css class
- Use menu link or onClick to set a variable
- functions.php is being included twice, creating PHP fatal errors
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Automatically remove a canceled order in Woocommerce
- Display fields as values in array from external SQL DB
- Only Show Link If div Exists
- How to put a variable in a instance in the widget
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Trying to establish connection to External Database
- add_action shortcut?
- Passing the custom field values in the wp_get_current_user array function
- Using fwrite() and “a” appends multiple times instead of once
- How to output a PHP file values by shortcode?