How to set the post title to my Name input field?
Support › MB Frontend Submission › How to set the post title to my Name input field?
- This topic has 11 replies, 2 voices, and was last updated 6 years, 11 months ago by
Anh Tran.
-
AuthorPosts
-
May 24, 2018 at 3:33 PM #9634
EddyPiV
ParticipantHi,
Probably a very basic question, with a very simple answer...
I am new to MB. Built my first meta boxes, and using the Frontend Submission extenstion to create a first post.
One of the fields is a Name field. Another field is "Elevator pitch"
How can I set the post title to this Name field?
Similar: how can I set the post extract to the value of "Elevator pitch"?I see a lot of coding in the documentation. I was expecting with all these extensions that I woulld not have to deal with this coding myself.
Thanks for your help.
May 24, 2018 at 3:44 PM #9635Anh Tran
KeymasterHello,
The post title is displayed in the
post_fields
attribute of the shortcode. Please use the MB Frontend Submission to add other fields to the form.In your situation, it sounds like changing the label for post title from "Post Title" to "Name".
So, please create a folder in your theme called
mb-frontend-submission
. Inside that folder, create a sub-folder calledpost
. And insidepost
, create a filetitle.php
, which contains the following code (don't worry, just copy and paste):<?php $title = $data->post_id ? get_post_field( 'post_title', $data->post_id ) : ''; $field = apply_filters( 'rwmb_frontend_post_title', array( 'type' => 'text', 'name' => esc_html__( 'Name', 'rwmb-frontend-submission' ), 'id' => 'post_title', 'std' => $title, ) ); $field = RWMB_Field::call( 'normalize', $field ); RWMB_Field::call( $field, 'admin_enqueue_scripts' ); RWMB_Field::call( 'show', $field, false, $data->post_id );
That's it!
Please try and let me know how it works.
May 24, 2018 at 5:27 PM #9648EddyPiV
ParticipantHi Anh,
Thanks for your very quick respons. Impressed!
Done as you requested, but no result.
See here the title.php that I created like you said.
https://1drv.ms/f/s!AiZg1q2e9vdxhBlxbs_Mz30DdS2cI have also tried with the same folder structure as for the template, like the Frontend Submission documentation describes.
So I tried with as well as without the folder "template-parts" in the middle.
No effect.May 24, 2018 at 5:40 PM #9649Anh Tran
KeymasterI see you use the folder
template-parts
. It should be without it (probably you did it, but please try again), like in this screenshot:https://i.imgur.com/WpmyMVI.png
I've just tested and here is the result:
May 25, 2018 at 5:23 PM #9666EddyPiV
ParticipantIt's not working unfortunately.
I added quite a number of fields in the meta box. For some reason, it is even no longer creating a post when I press the submit button.Let me know if you need access to the site.
May 25, 2018 at 6:30 PM #9671Anh Tran
KeymasterYes, please send me a temporary account to [email protected]. I’ll check it.
May 25, 2018 at 7:10 PM #9674EddyPiV
ParticipantDone. I have created a page frontend-submission.
Good luck.May 26, 2018 at 5:24 PM #9736Anh Tran
KeymasterI've checked on your site and I see you created a field with ID
post_title
. But as it's a field in a meta box, it can't be a post field.To add post field, you need to change the shortcode to:
[mb_frontend_form id="dominantgegevens,diensten" post_fields="title"]
And the template for post title now works.
Just a note: post fields (such as post title, editor, thumbnail, etc.) are not part of meta boxes, so you can't wrap it in tabs. They will appear above the tabs.
Here is the screenshot of the page:
May 27, 2018 at 3:18 PM #9768EddyPiV
ParticipantThanks, that works great. I now see how to fill the standard WP post attribues, except the Category. I have tried to use the fiels Taxanomy, but that shows me a dropdown box, while I just want to hide it and assign a fixed value to it.
Any suggestion?
(I understand that this is different from my original question. If you want me to close this one and open a new thread, let me know.)May 27, 2018 at 9:58 PM #9776Anh Tran
KeymasterHi,
To assign a fixed value to the category, use the taxonomy field. And set the default value (
std
parameter) to the category ID. Then that default value will be used when you submit the form.In order to hide the field, just add a custom CSS class to the field (like
hidden
) and add this line into your theme, or in Customizer > Additional CSS:.hidden { display: none; }
That's it. Please try and let me know how it goes.
May 27, 2018 at 10:16 PM #9778EddyPiV
ParticipantThe issue is that I don't understand how to set the default value to the category in the meta box. I don't see it in the options, and if I need to set it through custom attribute, then how?
May 28, 2018 at 2:30 PM #9800Anh Tran
KeymasterOops, the Default value is missed from the Builder. I'll fix it asap. In the mean time, you can set via custom attribute. Just set the key to
std
and the value to ID of the category:https://i.imgur.com/8xep7GQ.png
To get the category ID, see this screenshot:
-
AuthorPosts
- The topic ‘How to set the post title to my Name input field?’ is closed to new replies.