How can I display the form generated from the metabox?

I created a custom post type, with an associated custom meta box as per your guidance in here:

On the back-end I can see the meta box and everything works well.
My question is in regards to the front end, how can I display the form generated from the metabox?

If I use ACF fields, it’s quite simple, I can do the below for example.
But it would be much better if I can use the existing functionality of Hivepress rather than another plugin.

add_shortcode( 'frontend_form', 'display_frontend_form' );

function display_frontend_form() {

        'post_id'       => 'new_post',
        'post_title'    => true,
        'form' => true, 
        'new_post'      => array(
            'post_type'     => 'hp_company_profile',
            'post_status'   => 'pending'
        'field_groups' => array(2120),
        'submit_value'  => 'Submit'

    return ob_get_clean(); 


Yes, it can be done, but it will require advanced customization. The easiest option is to create a HivePress form (by creating a custom extension: Create a custom HivePress extension - Developer Docs) and add the $form->render() function. You can additionally view how the forms are made at this link: hivepress/includes/forms at master · hivepress/hivepress · GitHub. If the names of the meta fields with the hp prefix match, then you can use ACF without any problems, and if the validation is the same for the fields, then everything should be synchronized.

​I hope this is helpful to you.

Thank you Andrii, I will give it a try.

in regards to $form->render(), can I use it in a shortcode?
I am not sure how I can refer to the specific form in the shortcode function.

Or do I have to create a separate template as part of the custom extension?

Unfortunately there’s no way to call this function via a shortcode because it doesn’t execute custom PHP code, you’d have to create a custom shortcode and run any custom code in the shortcode callback function. If the form is already created via a custom HivePress extension then yes, it can be rendered via the template part or you can try using the “content” block type and provide the rendered form HTML in the “content” parameter of the block.

Hope this helps.

understood, thank you Ihor!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.