Home Forums Plugin Support WP User Frontend (Free Version) Save a custom field reading value from another

This topic is: resolved

This topic contains 18 replies, has 4 voices, and was last updated by  Tareq Hasan 5 years, 5 months ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #13248

    Danilo
    Participant
    Post count: 43

    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?

    #13249

    Mahi
    Member
    Post count: 1555

    Very much possible ๐Ÿ™‚

    Check action hook tutorial: http://docs.wedevs.com/using-action-hook-field/

    #13250

    Danilo
    Participant
    Post count: 43

    I saw this doc before, but I can't use it.
    You missed some information just like:
    – In which files I need to put the code?

    #13264

    Tareq Hasan
    Keymaster
    Post count: 2831

    You can put this code in your themes functions.php.

    #13292

    Danilo
    Participant
    Post count: 43

    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.
    Could you extend the tutorial with some examples?

    #13297

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #13305

    Danilo
    Participant
    Post count: 43

    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?

    #13307

    Tareq Hasan
    Keymaster
    Post count: 2831

    The link above exactly gives an example how to do that!

    #13309

    Danilo
    Participant
    Post count: 43

    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.

    #13324

    Denis
    Participant
    Post count: 165
    function hereTheNameOfYourFunchtion( $post_id ) {
        $titleTheUserPutsIn = get_post_meta( $post_id, 'post_title', true );
     
        update_post_meta( $post_id, 'yourCustomField', $titleTheUserPutsIn );
    }
     
    add_action( 'wpuf_add_post_after_insert', 'hereTheNameOfYourFunchtion' );
    add_action( 'wpuf_edit_post_after_update', 'hereTheNameOfYourFunchtion' );

    I think this will work.

    #13326

    Danilo
    Participant
    Post count: 43

    DenisCGN, I put your function but I get a blank key.
    My custom field is created, but is blank.

    I'm using the function with a hidden input field. Maybe this is the error?

    #13330

    Danilo
    Participant
    Post count: 43

    I publish my code, because a lot of ways, but my custom field is saved blank:
    [php]
    function render_posttitle( $form_id, $post_id, $form_settings ) {
    $value = get_post_meta( $post_id, ‘post_title', true );
    update_post_meta( $post_id, ‘meta_posttitle', $value );
    ?>
    <div class="wpuf-fields">
    <input type="hidden" name="my_posttitle" value="<?php echo esc_attr( $value ); ?>">
    </div>
    <?php
    }
    add_action( ‘hook_render_posttitle', ‘render_posttitle', 10, 3 );

    /* Write meta key */
    function get_posttitle( $post_id ) {
    if ( isset( $_POST[‘my_posttitle'] ) ) {
    update_post_meta( $post_id, ‘meta_posttitle', $_POST[‘my_posttitle'] );
    }
    }

    add_action( ‘wpuf_add_post_after_insert', ‘get_posttitle' );
    add_action( ‘wpuf_edit_post_after_update', ‘get_posttitle' );
    [/php]

    The code save always a blank key.

    #13331

    Danilo
    Participant
    Post count: 43

    Sorry, here is the code:
    http://pastebin.com/Zm5wEdY5

    Always a get a blank key.

    #13340

    Danilo
    Participant
    Post count: 43

    Definitively it doesn't work.
    Sorry, I'm trying all possibile combinations, I get always a blank key.

    #13348

    Tareq Hasan
    Keymaster
    Post count: 2831

    The post title in WordPress is not a meta field. So you can't get the post title via get_post_meta(), use get_post_field() for retrieving the post title.

Viewing 15 posts - 1 through 15 (of 19 total)

The topic ‘Save a custom field reading value from another’ is closed to new replies.