Associate authors programmatically
-
Hi, I am trying to programmatically associate authors for a given post of type ‘laboratory’ (it is a custom post type already defined in the system). Basically, to make a long story short, I am using the following code (considering ‘$user_01->ID’ and ‘$user_02->ID’ are the IDs of the two users I want to associate as post authors):
$my_post = array ( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $user->ID, 'post_title' => $title, 'post_status' => 'draft', 'post_type' => 'laboratory', ); // Creates the post of type 'laboratory' and gets its ID right after. $post_id = wp_insert_post( $my_post ); // ... and here is how I am trying to add coauthors: global $coauthors_plus; $coauthors_plus->add_coauthors( $post_id, array( $user_01->user_login, $user_02->user_login ), false );
This doesn’t work. The post of type ‘laboratory’ is actually created, but the global admin user is assigned as author, instead of the two coauthors. I have also tried passing user IDs for the add_coauthors function, with no success:
$coauthors_plus->add_coauthors( $post_id, array( $user_01->ID, $user_02->ID ), false );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Associate authors programmatically’ is closed to new replies.