Startseite › Toolset Professional Support › [Gelöst] Split: Display the value of a field instead of the field itself
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.
Dieses Thema wurde abgetrennt von https://toolset.com/de/forums/topic/display-the-value-of-a-field-instead-of-the-field-itself/
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
Verwandte Dokumentation:
Dieses Thema enthält 19 Antworten, hat 3 Stimmen.
Zuletzt aktualisiert von Minesh vor 6 Jahren.
Assistiert von: Minesh.
HI Luo yang,
Thx for that advice, it works as hoped!
I am however still unclear on the question of auto-filling the "submission details" field with the above value. The Submission details are actually the post title of the submission CPT and I need to fill it with the correct information. The idea would also be to hide the "submission details" field as this will be auto-filled.
If you would be so kind as to assist me with this.
Hi,
The Toolset form shortcode [cred_field] supports "value" attribute, so you can try these:
1) Create a content template "parent-requirement-title", with below codes:
[wpv-post-title item='[wpv-search-term param="parent_requirement_id"]']
2) Edit your Toolset form, add value attribute into title field shortcode [cred_field], like this:
[cred_field field="post_title" class="form-control" output="bootstrap" value='[wpv-post-body view_template="parent-requirement-title" suppress_filters="true"]']
And test again
More help:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
value. Optional. Preset value
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-body
Outputs the content of the current post or renders a content template
Sorry, you have lost me with your reply. Would it not be much simpler to add a function that will use the value of the parent field an use it fill the post title with? I have used a similar approach however it was a bit more simple as it was just field values I used to construct the post title with.
As it is not a text field I don't know how to bring it in.
The sample of the code I use here is what I used to set to post name for the actual parent post above. I just need some help with using the value of the parent post that is used above the content as a header
Here is a sample of the code i used:
/**This function adds the Document requirements per year per clients to the post title of the documents required per client */ add_action('cred_save_data','func_custom_post_title',10,2); function func_custom_post_title($post_id,$form_data) { if ($form_data['id']==138) { $docyear = get_post_meta($post_id, 'wpcf-year', true); $custname = get_post_meta($post_id, 'wpv-customer-requirement', true); $docname = get_post_meta($post_id, 'wpcf-document-master-list-requirement', true); $drdetail= $docyear. ' - ' . $custname. ' - ' . $docname; $args = array('ID' => $post_id, 'post_title' => $drdetail); wp_update_post($args); } }
Yes, you are right, it is possible with custom codes using Toolset form API hook "cred_save_data", in your custom PHP function func_custom_post_title($post_id,$form_data)
You can get the new post ID with var $post_id, use it to get the related parent "requirement" post ID with Types function toolset_get_related_post()
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
With "requirement" post ID to get what you want.
See similar thread here:
https://toolset.com/forums/topic/populate-child-post-title-with-parent-post-title/#post-908981
I Have tried using the following snippet of code but it is still not updating the post title of the child form.
<?php /** * New custom code snippet. */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); add_action('cred_save_data', 'save_data_form_175',10,2); function save_data_form_175($post_id, $form_data){ if ($form_data['id']==175) { $parentpost_id = toolset_get_related_post($post_id, 'relationshipslug' ); $parent_title = get_the_title($parentpost_id); $childpost_title = array( 'ID' => $post_id, 'post_title' => $parent_title, ); wp_update_post( $childpost_title ); } }
My child form being id 175, the field that needs to be updated of the child form is "post_title"
Luo is on vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.
Well - I see the following line with your code:
$parentpost_id = toolset_get_related_post($post_id, 'relationshipslug' );
have you replaced the actual "relationshipslug"? If yes, I need problem URL and access detail to debug this issue further.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Well - I see that you are having post relationship "requirement-submission", so I replaced the slug with the following code:
add_action('cred_save_data', 'save_data_form_175',10,2); function save_data_form_175($post_id, $form_data){ if ($form_data['id']==175) { $parentpost_id = toolset_get_related_post($post_id, 'requirement-submission'); $parent_title = get_the_title($parentpost_id); $childpost_title = array( 'ID' => $post_id, 'post_title' => $parent_title, ); wp_update_post( $childpost_title ); } }
Could you please confirm it works for you or your requirement is different?
HI MInesh,
It did work partially, however it made the post title"submit the documents. The post title should be the same as the post title of the parent post. I am attaching a print of the report with the post title. "submission image 2".
The title should, however, be the same as in the other screen print "submit page" the title of the post ie " 2018 - hashtag........"
Hope this clears up what i am trying to achieve.
Could you please share problem URL where I can see the form where it displays the parent post title? Could you please share direct link of that form?
Hi Minesh,
Here is the form where the ent4ry should happen.
versteckter Link
This is the form page where the source should come from:
versteckter Link
You click on the upload here link and it opens the above link.
In a Previous post I did supply login details as you can only access the screens when logged in
Could you please check now. I've adjusted the code at Toolset "Custom Code" section as given under:
=> versteckter Link
add_action('cred_save_data', 'save_data_form_175',10,2); function save_data_form_175($post_id, $form_data){ if ($form_data['id']==175) { $parentpost_id = toolset_get_related_post($post_id, 'requirement-submission','parent'); $parent_title = get_the_title($parentpost_id); $childpost_title = array( 'ID' => $post_id, 'post_title' => $parent_title, ); wp_update_post( $childpost_title ); } }
Additionally, I've assigned adjusted the code in form as given under:
<div class="form-group" Style="display: none;" > [cred_field field='@requirement-submission.parent' value="[wpv-search-term param='parent_requirement_id']" class='form-control' output='bootstrap' select_text='--- not set ---'] [cred_field field="form_messages" class="alert alert-warning"] </div>
Where I've added the value attribute and assigned the default value to parent field.
Could you please check now, it should work.
Hi MInesh,
Thx for your reply. I am still not getting the results needed.
Looking at the code for the form
[credform] <div class="form-group" Style="display: none;" > [cred_field field='@requirement-submission.parent' value="[wpv-search-term param='parent_requirement_id']" class='form-control' output='bootstrap' select_text='--- not set ---'] [cred_field field="form_messages" class="alert alert-warning"] </div> <h2>[wpv-post-title item='[wpv-search-term param="parent_requirement_id"]']</h2> [wpv-post-title] <div class="form-group"> <label>Submission detail</label> [cred_field field="post_title" class="form-control" output="bootstrap"] </div> <div class="form-group" style="disply:none"> <label>Date first uploaded</label> [cred_field field="date-first-uploaded" force_type="field" class="form-control" value="[wpv-post-today]" output="bootstrap"] </div> <div class="form-group" style="disply:none"> <label>Upload document</label> [cred_field field="upload-document" force_type="field" class="form-control" output="bootstrap"] </div> <div class="form-group" Style="display:none" > <label>Status</label> [cred_field field="status" force_type="field" class="form-control" output="bootstrap"] </div> [cred_field field="form_submit" output="bootstrap" value="Submit" class="btn btn-primary btn-lg"] [/credform]
I need this code to auto-fill the "post title" as I need the post title from the parent and the child to be the some. I have tried it and it still tells me the 'post title " required input.
Ahh, OK. So the code Luo shared is to update the post title once you submit the form but you want to display the post title with the input. I understand now.
But strange things is that I could not able to access your site: its showing HTTP ERROR 500 error.
I see you disable the view's plugin - are you working on the site?
Hi Minesh,
I updated the plugin and the views plugin caused a error 500. I have logged a support thread for it. If you activate the view plugin you will see the error message. I have activated wp-debug to show the error. I will then disable it once again to give access to the site