I am trying to create an "Edit Post Form" using CRED that only editors can use. The editor should be able to edit/update any content that the post currently has. I've successfully accomplished this part, but I'd like the editor to be able to select and update the author of the post.
For example, let's say we have a contributor create a post and it is saved as "Pending Review" I'd like the editor to be able to edit that post and change the author from the contributor who originally wrote the post to an editor that the post should belong to.
I visited this URL: https://toolset.com/forums/topic/cred-field-to-change-post-author/ and have followed the instructions.
I created a view to list all editors Loop is below:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=1]{"value":"[wpv-user field="ID"]","label":"[wpv-user field="display_name"]"}
[wpv-item index=other],{"value":"[wpv-user field="ID"]","label":"[wpv-user field="display_name"]"}
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
I created a CRED generic field that uses that view to populate my list and added it to my form id==289:
[cred_generic_field field='ha_select_editor' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="editor-author-list-view"] ]
}
[/cred_generic_field]
I also added the following to my 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 - Form 289 "Edit Post Form: Editor"
if ($form_data['id']==289) {
$my_post = array(
'ID' => $post_id,
'post_author' => $_POST['ha_select_editor']
);
// Update the post into the database
wp_update_post( $my_post );
}
}
I expected to see a select drop-down box on my form with a list of all of my editors.
Instead, I see no select drop-down box.
I've created a page for the view to make sure it was outputting the right data and it seems to be:
{"value":"1","label":"user"}
Am I missing a step or something?