anonymized-13171256
(@anonymized-13171256)
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.
@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??
anonymized-13171256
(@anonymized-13171256)
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?
Yes that sounds good . I dint think that way.
You are awesome 🙂 Thank you sooo much