Skip Navigation

[Resolved] Retain Author field value when editing it from the front end

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a generic field in a Form where Users can select from different post authors. It works fine in a new post Form, but in an edit post Form the select field does not display the selected value.

Solution: Use the wpv-post-author shortcode to pass the correct ID into the default attribute.

[cred_generic_field field='change_post_author' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[[wpv-post-author format='meta' meta='ID']],
"options":[ [wpv-view name="Tutti gli Utenti"] ]
}
  [/cred_generic_field]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author

This support ticket is created 5 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Silvia 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1106779
TASK.png

Hello, I am developing a project/event management website for my company. I want to have the ability to insert PROJECTS or EVENTS and assign them to a colleague, who is going to be responsible for the planning. Each Project or Event has one or more tasks that need to be assigned to different people based on the type of task (administrative, marketing, communication, logistics etc..)

I used the infos on this thread https://toolset.com/forums/topic/change-cp-author-on-frontend/ in order to be able to change the author assigned to a specific project or project task on the front end with Forms and it works ok except for one small thing.

Following the instructions I used this code in order to insert a generic field in the front end form

[cred_generic_field field='change_post_author' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="All Authors"] ]
}
[/cred_generic_field]

and whenever I display the form, the field has “unassigned” value. This is ok when I am inserting a new project or task.
Whenever I try to modify a project or task tho, the generic field shows the “unassigned” value even tho the task or project has been assigned to a specific author, in fact erasing the original value, even tho I might be editing that specific task or project to change a deadline date or other fields

I would like it to retain the value stored when I am modifying a task or project, and give the user the opportunity to change the original value or leave it as is.

#1106802

You can use the "default" attribute to specify the value that should be pre-selected in the Form. The value should be the post author's User ID. You can access that value with a wpv-post-author shortcode:

[wpv-post-author format="meta" meta="ID"]

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author
Depending on where this Form is placed, you may need to add the post's ID to the shortcode in an "id" attribute. If you give me some more context, I may be able to help with that. Is the Form in a View, or in a Content Template, or in a Template layout? What is the URL?

#1107493

Hello Christian, thanks for your answer!
Would it be ok if i granted you access to the website so that you can actually see what the problem is?

#1107610

Yes that will be fine. Private reply fields are available here. Let me know how I can find the Form on the front-end of the site.

#1107670

I made the change I described dfor you. Here's the updated code:

[cred_generic_field field='change_post_author' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[[wpv-post-author format='meta' meta='ID']],
"options":[ [wpv-view name="Tutti gli Utenti"] ]
}
  [/cred_generic_field]
#1107696

Thank you so much Christian,
I proceded to modifying the other form and now it stores values perfectly! Thanks a lot as usual!!

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