1

I have created a custom post and on the custom field I want to give value to name field in the back end, the post hasn't created yet and I wanted to create a field with name value so that the user can just input the value. please see the photo below, thanks...

Custom Fields

  • If you want to add your own with preset names, you can create a Custom Taxonomy or a Custom Meta Box. Otherwise, Castilblanco's solution has you covered. – WebElaine Aug 31 '18 at 17:36
  • You mean you want to create a metabox for your post meta? ( custom fields is just the name of that box in the UI, what you're talking about are post meta, all the APIs reference post meta, that it's called custom fields in the edit screen is just a user friendliness thing ) – Tom J Nowell Aug 31 '18 at 17:45
  • I'm sorry, but what I mean is the post hasn't created yet and I wanted to create the fields so that the user can just input the value. – Mute Glider Aug 31 '18 at 17:56
  • @MuteGlider most plugins use a metabox so that they don't need that interface, but it's all stored the same way. Custom meta boxes are what you need to research, trying to pre-fill the dropdown will be much harder even though metaboxes are better – Tom J Nowell Aug 31 '18 at 18:19
  • Thank you, I guess I just need to create another admin menu. – Mute Glider Aug 31 '18 at 18:28
0

Check this out.

You just have to click on Enter New and then you are going to be able to put the name and the value that you want, it's pretty intuitive.


Updated. Now that the OP clarified what he wants.


You will have to use add_post_meta, you will use it like this:

<?php add_post_meta( 68, 'my_key', '47', true ); ?>

The first argument is the $post_id, the second one is the $meta_key, the thirf one is the value $meta_value, and the last ($unique) one is a boolear whether or not you want the key to stay unique. When set to true, the custom field will not be added if the given key already exists among custom fields of the specified post.

  • Thank you for your response but, what I wanted to do is to add value using the back end programmatically – Mute Glider Aug 31 '18 at 17:36
  • @MuteGlider updated, the question title is wrong tho :p – Castiblanco Aug 31 '18 at 17:45
  • I'm sorry for that, but what I mean is the post hasn't created yet and I wanted to create the fields so that the user can just input the value. – Mute Glider Aug 31 '18 at 17:52
  • Check this, blog.teamtreehouse.com/… – Castiblanco Aug 31 '18 at 18:11
  • Thank you, I already know the ACF, I'm just wondering if I can programmatically code it and I guess ACF is the only way. – Mute Glider Aug 31 '18 at 18:25
0

@MuteGlider As was said by @WebElaine you should search for:

Custom Meta Boxes

.

Follow the documentation link: https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.