Skip Navigation

[Resolved] Allow editor to select appropriate author on CRED edit content form

This support ticket is created 7 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Fletch 7 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#439066

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?

#439220

Dear Fletch,

In the latest version of Views plugin, the shortcode [wpv-layout-start]...[wpv-layout-end] will output an extra HTML div tags, it will produce the problem as you mentioned above: no select drop-down box.

I suggest you try this:
1) create a shortcode to hide the extra DIV tag from Views ouptut, add below codes into your theme/functions.php:

add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
    return;
}

2) modify the codes in Views as below:

[hide-it][wpv-layout-start][/hide-it]
[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]
[hide-it][wpv-layout-end][/hide-it]

And test again

#439385

Thanks Luo,

I added the [hide-it] shortcode and now the drop-down shows up and lists my available editors like expected.

Unfortunately when I select an editor and push submit the post author isn't being saved / updating the post. When I return to edit the post the drop-down lists the author that I've selected in the previous step as the default option, but hitting submit doesn't change the post author on the actual post. Any thoughts?

#439842

The problem should be in the PHP codes, I suggest you manually debug it line by line, if you still assistance for it, please duplicate same problem in a test site, and fill below private detail box with login details and ftp access.

#440185

Thanks for the details, checking in your website, will feedback if there is anything found

#440190

In your CRED form, the author field is using name "ha_select_edior", but in your PHP codes, it is "ha_select_editor", so I simply modified the CRED form, line 39, modify it from:
[cred_generic_field field='ha_select_edior' type='select' class='' urlparam='']
To:
[cred_generic_field field='ha_select_editor' type='select' class='' urlparam='']

Please test again, check if it is fixed or not. thanks

#440395

Thanks for all of your help Luo! Sorry I missed the typo. Everything is working like it should.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.