Save a custom field reading value from another
Author | Posts |
---|---|
December 4, 2013 at 6:21 am 13248 | |
Tareq Hasan | Hi. I have a field as POST TITLE. I'd like to save another hidden field with same data entered in POST TITLE field, without action by the user. When user is publish its post, simply reading POST TITLE value and save the same value with hidden meta key. Is this possible? |
December 4, 2013 at 6:23 am 13249 | |
Mahi | Very much possible 🙂 Check action hook tutorial: http://docs.wedevs.com/using-action-hook-field/ |
December 4, 2013 at 6:27 am 13250 | |
Danilo | I saw this doc before, but I can’t use it. |
December 4, 2013 at 12:03 pm 13264 | |
Tareq Hasan | You can put this code in your themes |
December 4, 2013 at 7:13 pm 13292 | |
Danilo | First of all, thank you for support. But, in this tutorial, you explain basic usage. How can I read value from another field of the same form? Imagine that I put another field with date and I need to save another field with same entered date but with another format. |
December 4, 2013 at 7:51 pm 13297 | |
Tareq Hasan | Here’s another example of reading a value from another field and updating another 🙂 As you are getting post id, you can get post title based on the post id and update to another meta_key. |
December 4, 2013 at 8:37 pm 13305 | |
Danilo | Ok, it seems difficult but I’ll try today. How can I do the same with a date field, changing date format in a second field? |
December 4, 2013 at 9:00 pm 13307 | |
Tareq Hasan | The link above exactly gives an example how to do that! |
December 4, 2013 at 9:58 pm 13309 | |
Danilo | The snippet you send me is about Woocommerce product, so code is displaying _price meta. I can understand the example, but I need more information about how to retrieve another meta data, just like post title, and a lot of no-programmer user need this too… I can’t find much information in tutorial. |
December 5, 2013 at 12:47 am 13324 | |
Denis |
I think this will work. |
December 5, 2013 at 2:21 am 13326 | |
Danilo | DenisCGN, I put your function but I get a blank key. I’m using the function with a hidden input field. Maybe this is the error? |
December 5, 2013 at 3:38 am 13330 | |
Danilo | I publish my code, because a lot of ways, but my custom field is saved blank: /* Write meta key */ add_action( ‘wpuf_add_post_after_insert’, ‘get_posttitle’ ); The code save always a blank key. |
December 5, 2013 at 3:49 am 13331 | |
Danilo | Sorry, here is the code: Always a get a blank key. |
December 5, 2013 at 9:22 am 13340 | |
Danilo | Definitively it doesn’t work. |
December 5, 2013 at 11:55 am 13348 | |
Tareq Hasan | The post title in WordPress is not a meta field. So you can’t get the post title via |
December 6, 2013 at 9:29 am 13401 | |
Danilo | Sorry, but I can’t make this code to work! See latest version of my code here: How is wrong? |