You can use the transition_post_status
action for that. New posts transition from new
to auto-draft
, so we check for that condition to only add terms on that initial auto-save.
function wpd_add_post_terms( $new_status, $old_status, $post ) {
if( 'new' == $old_status && 'auto-draft' == $new_status ){
wp_set_post_terms( $post->ID, array( 42, 23 ), 'category' );
}
}
add_action( 'transition_post_status', 'wpd_add_post_terms', 10, 3 );
Related Posts:
- How do I append multiple taxonomies to the URL?
- Custom Taxonomy with Custom Post Type Finds No Posts
- Get custom post type by category in a page template
- Associating an “author” with a custom taxonomy
- TV Show database – Best way for structuring it?
- Correct way to use a form to to filter custom posts by taxonomy terms?
- Showing current taxonomy terms
- automatically create taxonomy with same name as post title
- Query posts by custom post type and custom taxonomy
- Custom Taxonomy conditionals
- After deleting a post are terms, and custom meta deleted?
- Best practice for adding posts in bulk
- WP 3.1 getting tax_query to work in query_posts()
- Programmatically adding posts
- Keep main articles and author blogs seprerate, News / Magazine like site
- Why is my custom loop not filtering correctly nor paginating?
- Custom post types with custom directories
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- How to customize admin posts based on the user who is logged in
- Show Two custom Post type and their posts on category page
- How to create an advanced filter search?
- Weird problem happening with custom taxonmy when creating/updating posts
- A question on creating filters for custom posts using taxonomy
- Conditional Query of Custom Post Type and custom taxonomy
- List custom taxonomy specific to one custom post type
- How do I move/order posts with a tag to the end?
- WordPress sort search results by custom order
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Hide parent categories when clicked, and show it’s childs
- How to add attributes to taxonomies that may be different from post to post?
- Migrating a taxonomy’s tags to the native category
- How to produce a sub-page-system in WordPress
- custom post type vs. conditionally displaying meta boxes for specific terms?
- List Categories (wp_terms) and count posts
- attach CPT data to a taxonomy
- Creating a non-hierarchical Taxonomy that behaves like categories
- Display Custom Post Types Glossary
- How should I structure complex content hierarchies?
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- Get terms for a specfic post from multiple taxonomies in custom post type
- How to list posts by term (custom taxonomy)
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Custom taxonomy not saving correctly
- Related “custom post type” using “custom taxonomy”
- How do I ensure that post_type and Taxonomy use the same slug?
- How do I disable the built-in editor and automatically configure the properties of new pages?
- How to have multiple search result pages in wordpress with taxonomy terms listed
- How can i display a taxonomy? i have created a plugin and then a custom type. and a taxonomy , also i have register it
- Set a Default CPT taxonomy by taxonomy id
- Building Link List for Custom Tax
- CPT: multiple loops with different terms
- Help with Travel Guide Setup
- WordPress query posts by custom post type not workng
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- WP_Query for CPT with filter by another WP_Query
- Sort by Custom Post Type (Multiple Loop)
- Get link for feed of specific post type AND taxonomy
- Inserting two categories
- Advise on Custom Taxonomies and Structure
- cannot export data from CPT UI (books)
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- How to develop Knowledge center in WordPress Website
- Custom Taxonomy as Dropdown in admin
- Custom Post type in separate database table for syncing
- Creating Photo Gallery System with Custom Post Type
- Custom Taxonomies Terms as Post Title for Custom Post Types upon Publishing
- Custom post type category, taxonomy and URL rewrite problem
- How can I remove categories in menu in custom post type?
- Custom Post Type: How to display all of same taxonomy?
- Get all posts WHERE custom_field is LIKE value
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Custom Post Type – List all attachments on Edit Screen
- Conditional Statement custom post type category
- Display Custom Toxonomy In WordPress and theme Widgets category selection dropdown list
- Dynamic dropdown select values depending on other custom field value
- Query Custom Post Type Taxonomy term with multiple parameters
- Post format alternative?
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- Rewrite custom post type with taxonomy
- how to count the current posts terms
- Displaying a custom post type using get_template_part into a specific layout
- Using page title as a link to term archive
- Add custom post type taxonomy tag to article class
- Custom Taxonomy dont save in a frontend form for post a custom post
- Setting Parent Page to Post
- Get the taxonomy value in the post loop inside the archive page
- How to display custom post type taxonomy in Contact Form 7 text field
- Custom Post Type & Taxonomies – Rewrite
- Custom Post Type and Structure Question
- How to show custom post count in archive page
- Change CPT permalink to use the category
- Custom Taxonomy is disabled on Edit page
- Delete attachment with post
- Why is this custom post type defaulting to archive.php?
- Get single object term for custom taxonomy
- Sorting custom post types by taxonomy (So close)
- Return Custom Post Type Categories
- ACF Relationship: Group posts by parent category term, then child [closed]