Design question about custom post types and taxonomies
-
I’m developing a plugin that registers a custom post type ‘question’. These posts contain taxonomy terms. The taxonomy ‘role’ is registered together with the custom post type using the ‘init’ hook. Works fine.
Now I want to create a number of these posts on plugin activation (using register_activation_hook). The posts are inserted into the database:
$post = array( 'post_title' => $value['Title'], 'post_status' => 'publish', 'post_type' => 'question', 'tax_input' => array( 'role' => array_map( 'trim', explode( ',', $value['Role'] )) ), 'meta_input' => array( '_competence_id'=> $value['Cid'] ) ); wp_insert_post( $post );
That works fine too, but the taxonomy isn’t saved because the taxonomy is registered only at the init hook which is after the activation hook.
So my question is: what’s the best approach to create these posts with their taxonomy on plugin activation?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Design question about custom post types and taxonomies’ is closed to new replies.