Title: Get entered data from fields for shortcode
Last modified: August 31, 2016

---

# Get entered data from fields for shortcode

 *  Resolved [Ryan Christenson](https://wordpress.org/support/users/gorkfu/)
 * (@gorkfu)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-entered-data-from-fields-for-shortcode/)
 * Let’s say I have three text fields; name, date, and price. When they are filled
   out I want to display some shortcode at the top of the metabox above the fields.
 * So if a user inputs:
    Name: Event 1 Date: 01/22/2016 Price: $19.99
 * I want a box above the fields inside the metabox to display this shortcode:
    [
   event-button name=”Event 1″ date=”01/22/2016″ price=”$19.99″]
 * Could this be done as a custom field? Also, if possible, how would it work for
   field groups?
 * [https://wordpress.org/plugins/cmb2/](https://wordpress.org/plugins/cmb2/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-entered-data-from-fields-for-shortcode/#post-7060683)
 * This is very rough and meant as more an illustration of how, not a final implementation.
 *     ```
       function barfoo( $object_id, $this ){
           $one = get_post_meta( $object_id, 'foo_text', true );
           $two = get_post_meta( $object_id, 'foo_textdate', true );
           $thr = get_post_meta( $object_id, 'foo_text_two', true );
   
           if ( ! empty( $one ) && ! empty( $two ) && ! empty( $thr ) ) {
               echo '[event-button name="' . $one . '" date="' . $two . '" price="' . $thr . '"]';
           }
       }
       add_action( "cmb2_before_post_form_02_test", 'barfoo' );
       ```
   
 * It uses this hook:
 *     ```
       do_action( "cmb2_before_{$object_type}_form_{$this->cmb_id}", $object_id, $this );
       ```
   
 * The 02_test part comes from the ID my local install has for the id param in new_cmb2_box().
   Allows you to specify the output for only specific metaboxes. Wrapped the output
   in the if statement in case you don’t have all the fields. Possible to also do
   it just for available/provided fields.
 * Customize as you see fit.
 *  Thread Starter [Ryan Christenson](https://wordpress.org/support/users/gorkfu/)
 * (@gorkfu)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-entered-data-from-fields-for-shortcode/#post-7060784)
 * Thanks Michael this helped a lot. I currently have this working and looping through
   a saved group. However, it would be nice to display each separate shortcode above
   the first repeatable field in a group. Is there any hook to repeat this inside
   a group?
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-entered-data-from-fields-for-shortcode/#post-7060792)
 * Not seeing any for after each group, to be honest. I have to wager due to the
   nature of how repeated groups are appended, not doing a hook there was considered
   not worth it.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Get entered data from fields for shortcode’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/get-entered-data-from-fields-for-shortcode/#post-7060792)
 * Status: resolved