How to use custom fields as custom values for hidden fields

I will have the form placed on a post that has the custom fields created with CustomPress. I would like to add the information of that custom fields as a hidden field to the form that is placed on that concrete custom post type. Is this possible? How can this be done?

Could you please provide a full example?

  • Ash
    • WordPress Hacker

    Hello Finca

    This has to be tricky. I am showing as per my example.

    I have created two custom fields using custompress:

    _ct_text_5babda91a627d and _ct_text_5babdaab9eb2e

    In the form, I have added two hidden fields with custom value and added values like the following:

    %_ct_text_5babda91a627d% and %_ct_text_5babdaab9eb2e%

    And then, I have added the following code:

    add_filter( 'forminator_field_hidden_field_value', function( $value, $saved_value, $field, $obj ) {

    global $post;

    if( $value == '%_ct_text_5babda91a627d%' ) {
    $value = get_post_meta( $post->ID, '_ct_text_5babda91a627d', true );
    }else if( $value == '%_ct_text_5babdaab9eb2e%' ) {
    $value = get_post_meta( $post->ID, '_ct_text_5babdaab9eb2e', true );
    }

    return $value;
    }, 99, 4 );

    You can use this code in your child theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Let us know if it works for you as well. Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,

    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.