• I want to automatically assign a specific cpt to a specific category.

    I’ve read various snippets of code, but can’t get any to work.

    The cpt is ‘item’ and the category is ‘magazine’.

    I’ve been trying to use this…

    function assign_item_category_automatically($post_ID) {
    	global $wpdb;
    	if(!wp_is_post_revision($post_ID)) {
    	wp_set_object_terms( $post_ID, 'magazine', 'category');
    	}
    }
    add_action('publish_item', 'assign_item_category_automatically');

The topic ‘Auto-assign cpt to category’ is closed to new replies.