Shortcode Not Showing in Front-end Post Submission
-
Hi,
I had created a multiple image upload metabox with my custom post type. I had applied it to my post type and everything is working nice. but I have a front-end submission form where I am trying to show image upload option but there always showing error “Metabox configuration is required to have an ID parameter.”. Can anyone please advice ? I am sharing my full code.add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' ); /** * Define the metabox and field configurations. */ function cmb2_sample_metaboxes() { // Start with an underscore to hide fields from custom fields list $prefix = '_pxlr_'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'pxlr-ticket-attachment', 'title' => __( 'Ticket Attchments', 'cmb2' ), 'object_types' => array( 'ticket', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default ) ); $cmb->add_field( array( 'name' => 'Add Attchments', 'desc' => 'Please attch your problem screenshot', 'id' => $prefix . 'ticket-attachment-list', 'type' => 'file_list', // 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 ) // Optional, override default text strings 'text' => array( 'add_upload_files_text' => 'Add or Upload Files', // default: "Add or Upload Files" 'remove_image_text' => 'Remove Image', // default: "Remove Image" 'file_text' => 'File', // default: "File:" 'file_download_text' => 'Download', // default: "Download" 'remove_text' => 'Remove', // default: "Remove" ), ) ); // Add other metaboxes as needed }
Created Shortcode with the following code
add_shortcode( 'pxlr-ticket-metabox-shortcode', 'pxlr_do_frontend_show_custom_metabox' ); /** * Shortcode to display a CMB2 form for a post ID. * @param array $atts Shortcode attributes * @return string Form HTML markup */ function pxlr_do_frontend_show_custom_metabox( $atts = array() ) { global $post; /** * Depending on your setup, check if the user has permissions to edit_posts */ if ( ! current_user_can( 'edit_posts' ) ) { return __( 'You do not have permissions to edit this post.', 'lang_domain' ); } /** * Make sure a WordPress post ID is set. * We'll default to the current post/page */ if ( ! isset( $atts['post_id'] ) ) { $atts['post_id'] = $post->ID; } // If no metabox id is set, yell about it if ( empty( $atts['id'] ) ) { return __( "Please add an 'id' attribute to specify the CMB2 form to display.", 'lang_domain' ); } $metabox_id = esc_attr( $atts['id'] ); // $object_id = absint( $atts['post_id'] ); // Get our form $form = cmb2_get_metabox_form( $metabox_id ); return $form; }
And in my post type submission template I had applied this
<?php echo do_shortcode('[pxlr-ticket-metabox-shortcode id="pxlr-ticket-attachment"]')?>
Always showing same error. So I am confused. Is there anything I missed ?
Also for post submission front-end form is there anything I have to follow ?
Thanks in Advance for your valuable time and great support.
- The topic ‘Shortcode Not Showing in Front-end Post Submission’ is closed to new replies.