In save_post
action you can access to the objet of the saved post and check the post type before tagging it:
add_action( 'save_post', 'add_authors_name', 10, 2 );
function add_authors_name( $post_id, $post ) {
// The post types you want be tagged to $valid_post_types array
$valid_post_types = array( 'post', 'community' );
if( in_array( $post->post_type, $valid_post_types) ) {
$post_author = $post->post_author; // returns the Author ID
// get the author's WP_User object so we can get the Author Name
$post_author_obj = get_userdata( $post_author );
$post_author_name = $post_author_obj->first_name . ' ' . $post_author_obj->last_name;
if( ! has_term( $post_author_name, 'post_tag', $post ) ) {
wp_set_post_terms( $post_id, $post_author_name, 'post_tag', true );
}
}
}
Related Posts:
- Find callback function for custom taxonomy metabox
- Custom posts – tag pagination
- display custom portfolio tags
- Tag template not returning posts [closed]
- CPT tags not showing when editing post
- How to convert Post Object Custom Field into Tags
- Searching multiple custom post types and pages
- List all the tags from a custom post type
- expire wordpress user posts
- Adding post tags to custom post types
- show tags of custom post type ONLY
- Forcing all posts associated with a custom post type to be private
- TV Show database – Best way for structuring it?
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page
- Best way to style first post differently?
- How to create user personal pages with information from their meta profile fields?
- Adding An Author Tag To Posts Automatically
- if && problems with transition_post_status
- custom post type upcoming post and past post
- Add multiple custom post types in functions.php, but only one custom post type show in dashboard
- associate custom post type with tags with specific pages
- Display only custom post type count for current author on the “At a Glance” dashboard widget
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- remove child post from custom post type archive
- How would I create a shortcode to display a custom post within a page or regular post?
- How to make a custom taxonomy selectable in post publish area?
- Add Tags to custom post type
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Filter categories of posts with checkboxes
- WooCommerce product search titles only
- Remove standard meta boxes from custom taxonomy
- Group posts by custom post type
- Making a custom help center page
- create a template page for a post
- custom post type not showing in menu
- Show category ID on custom post type
- Custom post type getting wrong categories and tags
- Change CPT archive title
- AJAX load more for different custom post type loops
- Featured image overlay when changing post status
- How to display “Category and Post_tag” component in a CPT Gutenberg edit screen?
- Static page determines as home, but it is not
- Cannot save CPT meta box
- next_/previous_post_link() `in_same_category` appears to fail when true
- Want to be able to sign up subscribers as authors
- categories should be available across all custom post types
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- custom post for slider
- How to display custom post type tags?
- Excerpt function for any content
- Navigate posts with different post type that are in the same categories
- Display an authors post on a single page only when they are logged in
- Tags not working in my custom post type
- Page Template Dropdown For Custom Post Types
- Show Custom Message in WordPress Admin
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- providing access to post_id or post inside functions.php
- Is it possible to use array_walk() to append terms to an array of posts?
- WordPress notification if new post published
- URL Rewrite – Page Archive
- post_content is stripping HTML when adding a new post? [closed]
- Function to limit number of custom post types on homepage – TwentyTen
- custom post creation on front page – on submit a search is done
- How to setup different permlalinks for posts and pages?
- display custom post on separate page
- Post type Echo code is repeating on homepage
- new post-type how do i retain the plugins on my sidebar?
- Custom Post Type Dashboard Tab not displaying any posts
- Exclude a specific post in a Custom Post Type
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- Assigning categories to custom post types via a front-end form; only works for native post type
- Add custom template ‘sub-page’ to Custom Post type?
- How to set “section categories”?
- Custom Post Type Single Page and Archive Page redirects to Home Page
- From CPT Custom Loop into Shortcode?
- Disable Sidebar on certain pages
- Skip latest 3 posts from loop
- Load custom post type with ID in a shortcode
- How to assign post to category
- Automatically / dynamically populating tags in custom post type
- If thumbnail image else post title
- $_SESSION Not working after X amount of page views
- Different Configuration for the_excerpt()
- WordPress page not showing up – replaced with last 10 posts?
- How to mark posts as visited
- can’t see categories in appearance-menu-categories
- Different post types arranged on one page
- Use Tags to Query Associated Multiple Posts and Get The Average Of Custom Field Values
- How can I include custom post types on a tag page?
- Loop multiple taxonomy in custom post
- Generating List of Tags from Custom Post Type
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- send email to all registered users when post expires
- Custom Post Type Tags Showing Under Regular Post Tags
- Return all wordpress custom posts in specific multidimensional array
- Using custom post types within a section of a template
- show 10 most recent custom post types excluding the one(s) from specific custom taxonomy
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs