Use the ‘save_post’ hook to programmatically enteract with your new post when it is created, then use the wp_set_post_terms()
function to assign your term,
add_action('save_post','set_post_default_category', 10,3);
function set_post_default_category($post_id, $post, $update){
if($update) return; //only want to set if this is a new post!
if('post' !== $post->post_type) return; //only set for post_type = post!
$term = get_term_by('slug', 'my-custom-term', 'category');//get the default term using the slug, its more portable!
wp_set_post_terms( $post_id, $term->term_id, 'category', true );
}
Related Posts:
- Force category choice before creating new post?
- Add search to list of categories in post editor
- Hide tag and category boxes from the post editor
- Hide Some Categories in Post Editor
- Woocommerce Force the category choice before creating new product? [duplicate]
- WordPress Multisite – global categories
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Can’t custom taxonomies have same terms (slugs) as categories?
- Using wp_category_checklist in a widget
- How to show subcategories in categories else show posts
- How to remove the parentheses from the category widget
- Filter front page posts by category
- How to get the url to tag & category base set by the user?
- Exclude one category from get_the_term_list
- WordPress remove separator from last item in wp_list_categories
- Need help adding custom field to category
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Root level category, tag, author and archive pages to work
- Number of posts in page – set per category and exclude sidebar
- Display one latest post from multiple categories
- Archive pagination causing 404 with permalinks structure
- Use get_term_children to get the sub category of a parent category for the current post
- Get a list of Terms for a specific category
- Get a variable from object in array [closed]
- How to stop wordpress from showing the selected category on top of others in the category selection?
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- advanced custom field Show field in special categry page [closed]
- Exclude Child Categories Using wp_list_categories
- a-z list, categories and sub categories in loop
- Category slug $_SERVER[‘REQUEST_URI’];
- wp_dropdown_categories and custom taxonomy + custom post type
- How do I get a list of all categories that a given user has written blog posts for?
- Linking products to categories
- How to remove “Category : …”
- Show all posts for a specific category/author
- Add “page-a” slug to category link if user visit category link from “page-a”
- How to call custom category field data in theme?
- Query Posts Exclude Entire Category
- One Specific Category To Permalink
- Hide woocommerce category name from specific pages
- select parent category first then child
- WordPress category widget only show categories with children
- Woocommerce custom category page with pagination [closed]
- Menus don’t work after 4.4 [closed]
- Custom post and category template pagination problem
- Multiple category selection in post, shows less important category in breadcrumb
- I want to display the all the posts that are inside a certain subcategory
- How to list all categories in three divs dynamically based on the quatity of categories?
- Grouping categories by genre
- how to “not” display new posts with a specific category on the main page?
- Category template with pagination returns 404 on next pages
- Limit categories and it’s subcategories for specific group of users
- show all WordPress categories in a page
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Category specific order
- Problems with my conditionals in single.php by category
- Recent post by custom select query
- WP_safe_redirect not working
- Do not show sub categories in the loop on archive-product.php
- Having a template per category? Bad for server overhead?
- Add custom code at start and end of all posts in a category
- Posts from a category on homepage with category archieves page default css
- How to use wp_list_categories with plugin category?
- Theme modification for custom category menus
- Custom css per category and per single post belong in each category
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- Limit Loop to One Category
- wordpress taxonomy query posts
- Subcategory is displayed before Parent Category
- Shortcode to display all the post from a category in a page
- Custom Loop with certain number of one category
- “Special” category is displayed in all categories or show parent category on sub category
- How to show WooCommerce Categories on ‘shop’ page instead of products?
- How to list all subcategories from all categories but not from a certain category
- add woocommerce archive description if exist
- Can’t display posts by filtering categories using isotope.js
- Get a list of categories, separated by / to display inside the for custom metatags
- Automatically create tags and merge with categories
- Is there a reason to put a product in both the Child and Parent Categories?
- Get_term_meta() always returns false
- How to list all categories a post is in, but exclude current post´s category on single post page
- Get only children category name
- No results found for second level category
- get_the_category vs wp_get_post_categories
- Categories in media library
- WordPress Shop and restricting products and categories for some users/groups
- Pass list of categories to JS
- WP_query exclude a category unless it has more than one catagory
- Customize category query in widget
- Page permalink rewrite
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- How to control order when displaying child categories
- Broken category styling
- Trying to WP_Query a category
- How to get specific number of category post on a page or category page?
- Use same wordpress category base and tags as the prefix as the post permalink
- Display different sidebar based on search results from one category
- Adding category to existing post (uploaded file)
- how to create a page that shows all of multiple category posts on a single page
- Quick Edit on taxonomy names results in error