How to include current post title on a form

Support MB Frontend Submission How to include current post title on a form

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10147
    dewabalidewabali
    Participant

    Hi,I already try to find any tutorial about including current post title on front end submission.

    My goal is :
    - create booking form using MB frontend submission
    - place the shortcode on sidebar
    - Use the post title as one of the field value, example user visit page with title "Karala 3 Days Tour" <= I want this title automatically include in my form and it will be uneditable

    Anyone, please help

    #10167
    davidrknowlesdavidrknowles
    Participant

    I tried this and I thought get_the_title(get_the_ID()) might work as an std but it doesn't, mainly I think due to when the filter fires.

    But I think what might work is using one of the hooks, try this:

    add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
        if ( 'my-meta-box' === $config['id'] ) {
            $sub_title = get_the_title(get_the_ID());
            update_post_meta($post_id, 'submitted_from',  $sub_title);
        }
    }, 10, 2 );

    Change "my-meta-box" to your overall meta_box id,
    change "submitted_from" to the field you want to populate.

    If you don't want this field to show on the front end you may have to manually hide it.

    Hope this helps you.

    #10169
    dewabalidewabali
    Participant

    Hi, thanks for your effort, will try this and get back to you to report the result

    #10201
    dewabalidewabali
    Participant

    It works. Thanks Buddy

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘How to include current post title on a form’ is closed to new replies.