I recently ran into a similar situation. While I can’t currently remember the source, the code below will create a new entry into your taxonomy of choice, it could serve as the base for your needs.
//Automatically creates a category in the case log and adds it to the post.
function add_title_as_category( $postid ) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
$post = get_post($postid);
if ( $post->post_type == 'case') { // change 'post' to any cpt you want to target
$term = get_term_by('slug', $post->post_name, 'case-log');
if ( empty($term) ) {
$add = wp_insert_term( $post->post_title, 'case-log', array('slug'=> $post->post_name) );
if ( is_array($add) && isset($add['term_id']) ) {
wp_set_object_terms($postid, $add['term_id'], 'case-log', true );
}
}
}
}
add_action(‘save_post’, ‘add_title_as_category’);
Related Posts:
- Get The Post Type A Taxonomy Is Attached To
- Shouldn’t this be easy?! Custom post type/custom taxonomy permalink
- Custom Post type & Taxonomy URL structure
- How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy
- Check if a custom taxonomy archive page is being displayed
- How to limit the number of terms (terms acts like categories)
- How can I list all the categories under a Custom Post Type (taxonomy)?
- Two Custom Post Types, Share Two Taxonomies
- Semantic URL Custom Post Type and Taxonomies permalinks
- Displaying Posts Related to Other Posts by a Taxonomy Term?
- Add custom taxonomy to custom post type
- How do I add a custom post type to the Featured Content in twenty fourteen theme?
- Ajax filter with custom taxonomies
- Querying Posts by Taxonomy From Alternate Network Site
- Is there An Input Checkbox Option That Works like `wp_dropdown_categories()` To Use In A WP Search Form?
- Is slug “type” reserved and can’t be used in taxonomy rewrite?
- Adding Custom Taxonomy Archive Link to Nav Menu Shows Up As (Invalid)
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- Permalinks when filtering multiple custom post types by single taxonomy
- Filter custom post type archive page with custom taxonomies (categories) with AJAX
- CPT Search Form with Taxonomy filter & Or
- How-to leverage WordPress for creating Extended Social Profiles
- Weird problem happening with custom taxonmy when creating/updating posts
- How To Create A Custom Taxonomy 404 Page
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- $wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
- Query Multiple Taxominies Across Multiple Post type’s
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Overriding taxonomy and custom post type
- Custom Post hierarchical to custom taxonomy
- How to use custom taxonomies to reference complex relationships?
- How to checked selected category checkbox when my custom post inserted from frontend
- Specific query for custom post type
- How to edit this code to get the categories in achieve page?
- Get general taxonomy name for a Custom Post Type
- WordPress uses url different from defined in rewrite arg of custom post type
- List Taxonomy Terms based on another Taxonomy
- Display taxonomy terms, child terms and posts in a template
- Ordering values entered in Custom Taxonomies
- Show fields based on taxonomy selection in editor
- Permalinks: custom structure for taxonomy – tags?
- How to get WordPress term attached to the Post?
- Add “Select All” to custom taxonomy
- Disable custom taxonomy on admin bar
- How can I merge this function(s) that inserts terms to a custom taxonomy with this other that adds a custom taxonomy filter?
- how to show records that don’t have custom meta value
- how to get this tax_query working?
- Empty taxonomy items for CPT in admin grid
- How to get_term_meta on single custom post?
- Add term slug in URL of custom post type details page
- Custom post type and custom taxonomy 404 on page 2
- Ideas on how to organize a project [closed]
- Query only current post type using taxonomy
- Template for custom taxonomy for custom post type broken
- How should I structure complex content hierarchies?
- Querying two different post types with the same taxonomony
- Change permalinks for custom post type based on taxonomy term
- Convert Custom Taxonomy Posts to Normal Posts
- Custom Post taxonomy template
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- Using get_terms() to list terms from one custom taxonomy AND from one specific built-in category
- set object terms after some some time of published post – functions.php
- Is there a way to use ‘publicly_queryable’ => false only on specific taxonomy term?
- Right way to store a large set of similar information on website? [duplicate]
- How to prefix custom post type URL with custom post taxonomy term?
- How to debug failing updates for custom post type?
- Posts per Page on custom Taxonomy Template
- Set up Custom Taxonomy Archive Template File To Cover 3 Categories
- Display 3 level taxonomies
- Recovering data about custom post and taxonomy types
- WP_query sort by taxonomy
- Custom Post didn’t display on tags page
- Custom fields for taxonomies with custom value for each post
- Custom Post Type / Taxonomy / Term – what template to use to avoid 404-page?
- Add Custom Term to RSS Feed Titles
- If custom taxonomy exist on post?
- Pagination not working (page/2 retunring 404 page)
- How to show post which has the specific taxonomy terms?
- Custom Post Hierarchy and users
- Breadcrumb that shows multiple custom taxonomies
- WordPress add taxonomies/terms list as a menu in archive page
- YearWise Categorywise Post
- Hide Custom Taxonomy title if not associated with another Custom Taxomony
- How to add base permalink to custom posts?
- How to query posts by meta keys AND under specific category?
- Shortcode display CPT Query only showing 1 post?
- Query Posts with Custom Taxonomy from a Custom Post Type
- How to show a custom taxonomy using a custom template
- Get Registered Custom Post Type to get All Custom Taxonomies
- Parent cpt/child custom post type URL permalink relationship
- Issue on Adding Taxonomy to Custom Post Type Using Function
- Show custom taxonomies in admin panel under custom post type
- Plugins for putting Custom Post Types into the Menu
- Custom term link return 404 error
- Remove slug from Custom Category Permalink + dual-category permalinks
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Display associated taxonomy child name on single CPT page
- Display ONLY ONE $term (Out of 4 terms) from a Custom Taxonomy and CPT
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- Problem with shortcode