I am categorizing a custom posttype by a taxonomy (More Taxonomies) term for year. What I want is my custom post type to have the current year automatically selected as a default taxonomy term when I’m going to add a new post.
So, in pseudo code I would like the to set default taxonomy term for custom post type where term name is date(“Y”).
Any ideas how I can do this, and/or how to set default taxonomy term?
You can use the following:
Notes:
{post_type}
to your post type’s name. So if your post type is “project”, the action should besave_post_project
{taxonomy}
to your taxonomy’s name, for examplewp_set_object_terms( $post_id, date( 'Y' ), 'project-year', true );
date( 'Y' )
to'project-posted-in-' . date( 'Y' )