I’m building a site with two separate CPTs nominees and winners

The idea is that we have a user submit a nomination in one of 7 categories ( taxonomy ) on the front end, and editors go in and approve nominations for display on the website.

Once every quarter, a selection of 7 nominees ( one from each category ) are chosen as winners.

Is there a way to copy the fields from a nominee CPT ( name, department, taxonomy, content ) to a winner CPT? Ideally, this would be done by a call in the Admin.

2 Answers
2

You can update a posts type using wp_update_post:

$my_post = array(
    'ID'        => $post_id,
    'post_type' => 'winner',
);
wp_update_post( $my_post, true );

// check if it failed and tell the user why
if ( is_wp_error( $post_id ) ) {
    $errors = $post_id->get_error_messages();
    foreach ( $errors as $error ) {
        echo 'error: '.esc_html( $error );
    }
}

Where $post_id is the ID of the post you’re switching to

Leave a Reply

Your email address will not be published. Required fields are marked *