也许这就是你要找的?
源来自@Michael Fields
/**
* Set default cat for cpt
* @source {https://circlecube.com/says/2013/01/set-default-terms-for-your-custom-taxonomy-default/}
* @source {http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/}
* @license GPLv2
*/
function set_default_object_terms_203962( $post_id, $post ) {
if ( \'publish\' === $post->post_status ) {
$defaults = array(
//\'your_taxonomy_id\' => array( \'your_term_slug\', \'your_term_slug\' )
\'post_tag\' => array( \'taco\', \'banana\' ),
\'monkey-faces\' => array( \'see-no-evil\' ),
);
$taxonomies = get_object_taxonomies( $post->post_type );
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $post_id, $taxonomy );
if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy );
}
}}
}
add_action( \'save_post\', \'set_default_object_terms_203962\', 100, 2 );
这对我们很有吸引力。
ps,还有一个plugin 这可能有助于在用户(阅读编辑/作者等)甚至可以发布之前“强制”你的一些愿望