• Resolved siddheshsj

    (@siddheshsj)


    I have created shortcode to display date on the form.
    But when i submit the form “date” is not added to db table ‘wp-postmeta’.
    Can anyone please shed light on this why it is not get added, as its really urgent.
    Also if there is a way(code example) i can retrive and display the date using shortcode.
    Any help appreciated. I have added code below along with screenshot

    Thank you in advance

    Code:
    function shortcode_datepicker()
    {
    ?>
    <script>
    $(function() {
    $( “#datepicker1” ).datepicker({
    });
    });
    </script>
    <input type = “text” id = “datepicker1″ name=”datepicker1”>

    <?php
    }
    add_shortcode( ‘custom_datepicker’, ‘shortcode_datepicker’ );

    form field added using shortcode

    • This topic was modified 7 years, 8 months ago by siddheshsj.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Chris Dillon

    (@cdillon27)

    The field is not added to the database because the plugin doesn’t know what the shortcode does.

    The next step is to append the new date to the other fields:

    /**
     * Add datepicker field to new testimonial post meta fields.
     * 
     * @param $new_meta array
     *
     * @return array
     */
    function custom_datepicker_add_meta( $new_meta ) {
      if ( isset( $_POST['datepicker1'] ) && $_POST['datepicker1'] ) {
        $new_meta['datepicker1'] = $_POST['datepicker1'];
      }
      return $new_meta;
    }
    add_filter( 'wpmtst_new_testimonial_meta', 'custom_datepicker_add_meta' );

    You will need another shortcode to retrieve and display the date.

    A simpler approach would be to use a plain text field and attach the datepicker to that.

    function my_datepicker( $atts ) {
      wp_enqueue_script( 'jquery-ui-datepicker' );
      ?>
      <script>
        jQuery(function () {
          // use your date field's id
          jQuery('#wpmtst_newdate').datepicker({})
        })
      </script>
      <?php
    }
    add_action( 'wpmtst_form_rendered', 'my_datepicker' );

    That will make the date field available in the post meta box and the view editor so you can display it like any other field.

    Thread Starter siddheshsj

    (@siddheshsj)

    @chris Dillon

    Thanks alot for your help. Much appreciated

    First filter function which you gave is working perfectly fine.
    Can you please tell where to put function(hook:wpmtst_form_rendered) for display( i mean file wherein i can put)
    Also i was trying to display date stored in db on testimonial slider which is available by default along with rest of the fields.
    Do i need to write shortcode( consisting of wp_query) to fetch date for each postid everytime??

    Plugin Contributor Chris Dillon

    (@cdillon27)

    Let’s take a step back.

    If you want to add a date field, you don’t need to use a shortcode field.

    Instead, try this. Add a plain text field and attach datepicker to it using the second function above. That would go in your theme’s functions.php or an mu-plugin. Change “newdate” to your field name.

    Then the date field will be available everywhere with the rest of the fields.

    Does that make sense?

    Thread Starter siddheshsj

    (@siddheshsj)

    Yes that sounds good . I dint think that way.
    You are awesome ?? Thank you sooo much

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Special field shortcode’ is closed to new replies.