Problem:
The issue here is that the user wanted to assign his post authors through the frontend.
Solution:
This solution requires multiple steps.
The first is to create a CRED form for the post to update the authors and then add a generic field like this to the Form
<label>Kies klant</label>
[cred_generic_field field="my_autor_select" type="select" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="View Name"] ]
}
[/cred_generic_field]
Notice that we have a view populating the generic dropdown list. So our CRED generic field gets the information for the Select dropdown in JSON format so you will need to create your view and format it like this.
<wpv-loop>
[wpv-item index=1] {"value":"[wpv-user field="ID"]","label":"[wpv-user field="nickname"]"}[wpv-item index=other],{"value":"[wpv-user field="ID"]","label":"[wpv-user field="nickname"]"} </wpv-loop>
Next in order for the view to be able to provide a clean output for CRED you will need this function below. Add it to your functions.php file
// FILTER OM HET TE LATEN ZIEN
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
if ( $id == '109' ) { //Please adjust to your Views ID
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}
Replace the ID 109 with the ID of your view.
Now finally in order for it to update the author you will need to write a CRED hook for that generic field. Add the following to your functions.php file
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==48)
{
$my_post = array(
'ID' => $post_id,
'post_author' => $_POST['my_autor_select']
);
// Update the post into the database
wp_update_post( $my_post );
}
}
Replace the 48 with your CRED form ID and it should work.