You’re almost there – the problem is you’re trying to access the $post
object when the function only receives the post ID.
add_action( 'publish_country', 'add_country_term' );
function add_country_term( $post_ID ) {
$post = get_post( $post_ID ); // get post object
wp_insert_term( $post->post_title, 'country_taxo' );
}
Related Posts:
- pre get posts changing the query
- Using pre_get_posts to Filter Posts
- Displaying custom taxonomy in the admin list of a custom post type
- How to Add Custom Taxonomy To Woocommerce Plugin
- Exclude a category from WP_Query
- Check if post type has term
- Custom taxonomy not showing up when adding a new custom post type
- query multiple taxonomies
- wp_set_object_terms() is not replacing term, but creating a new one
- WordPress custom taxonomy URL rewrite on spelling errors
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- TV Show database – Best way for structuring it?
- Create an archive page for custom taxonomies
- custom post type taxonomies UI radiobuttons not checkboxes
- Custom Post Type Archive Template
- Order posts by (hierarchical custom) taxonomy terms and term children
- Filter get_categories() for taxonomy term in WordPress
- Custom search for custom post type, custom meta and search fields
- Taxonomy-{taxnonomy}.php is not working
- Add the .html extension to custom post types
- After deleting a post are terms, and custom meta deleted?
- Show metabox in custom-post-template depending on taxonomy term?
- How to add custom fields to admin UI and REST API response?
- Custom Permalink for Taxonimie and Custom Post Type
- Adding the taxonomy before the custom post type
- Custom Taxonomy term archive template
- how can i get posts from custom post type particular taxonomy category
- Permalink Structure CPT With Custom Taxonomy Fails
- Conditionally custom post type url rewrite
- How do I create filters for custom post types?
- Root slug of taxonomy returning 404
- Multiple portfolios and single item in two of them (ideas?)
- Pagination for Custom Taxonomy Page [duplicate]
- Display custom post type category, while in a CPT category, then the posts beneath
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Hide post navigation if current post is in a category with only one post
- I want to change the word “Tags” in WordPress to something else, but how?
- How to have this permalink structure: post_type/postname/custom_inner_page
- Set post terms for multiple posts
- Custom permalink with child taxonomy terms
- Display Registered Taxonomies
- Custom Taxonomy Not Showing in Front-End When Outputting a Custom Post Type with WP_Query()
- Pagination Not Working for Custom Taxonomy with Custom Query – 404 Error
- Custom Taxonomy Is Being Pulled into a Page, But It Doesn’t Have A Hyperlink
- Querying two taxonomies with tax_query not woking
- Display custom posts randomly in custom taxonomy archive
- WP_Query parameter conflict
- How to get all posts related to particular category name on button click?
- Urls in Custom Post Type work for Terms but not for its Taxonomies
- List all Custom Post Type posts excluding certain Taxnomy term
- Display custom posts for each category from its custom taxonomy
- Get custom category ID of current custom post within the loop
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Conditional Statements
- Add filter to Admin list for all custom post types by their custom taxonomies
- Single.php for Custom Post Type > Taxonomy > Term
- Get newest created custom category (get_term_by and variables) (outside Loop)
- Custom Taxonomy Taxonomies of Same Name point to first created URL
- Displaying custom taxonomy menu in custom post type archive
- Custom post types templates
- prevent sub categories to show up
- Taxonomy terms with the same name are updated between separate custom post types
- Custom taxonomy permalink without term, redirection to CPT slug
- Custom post type category link redirecting to 404 page
- Using `set_transient()` when saving a custom post type
- Archive page URL for custom taxonomy and post type
- Display post count for a specific month
- Custom Post Type Archive Page showing as 404
- Custom taxonomy terms hierarchical navigation
- Create custom post type categories
- Dynamically Adding Posts of Post Type to A List
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Add other all taxonomies as meta boxes to custom post type
- How to get post type archive category title
- Remove CPT Slug with 2 taxonomies and 1 post meta
- URL with Hierarchical Taxonomies and same slug for all terms and sub-terms
- Should I make a taxonomy to organize data like this?
- Display Custom taxonomy, Child terms and posts in a template Under Specific Parent terms
- Associate custom categories to different user IDs
- List all posts from custom post type by taxonomy
- archive-{custom_post_type}.php not getting recognized wordpress
- How to retrieve the permalink for a specific (custom) term?
- Values inside a custom field to determine which category posts to display
- changing post type in loop query
- Taxonomy and Rewrite Structure
- Pagination for a Custom Taxonomy
- Trying to create hierarchy between 3-4 custom post types
- title tag for custom post type remove taxonomy name from title tag
- Add custom taxonomies as class names to an archive page of custom post types
- What is the proper way implement a global $wp_rewrite?
- Create a page selector using taxonomies
- Custom Post Type Base URL
- Only One Post of Custom Post Type Appearing on Template Page
- Code to show related posts (custom post type and custom taxonomy/category) is messing with other code
- register_term_meta not working
- Limit taxonomy terms added to a custom post type
- I want to understand plugin implementation of custom posts / taxonomies / metaboxes
- Dynamically count the number of custom post types associated to a custom taxonomy