Support

Account

Home Forums Search Search Results for 'date picker'

Search Results for 'date picker'

reply

  • Hi @cerulean

    The display_format is only for use in the back-end. It is not what is returned to you via the API.

    To format the date object, please follow the code examples on the date picker documentation page.

    Thanks
    Elliot

  • save_post() works fine in 4.1.8, and doesn’t create any errors. Here’s XDebug Context for ACF 4.1.8 , breakpoint at $f = apply_filters('acf/load_field', false, $k ); in acf.php:save_post( $post_id )

    Inside the loop, 1st iteration (single date and time picker field):

    
    $f = array[18]
    	$f['name'] = (string) dato
    	$f['class'] = (string) date_time_picker
    	$f['time_format'] = (string) H:mm
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[2]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    		$f['conditional_logic']['status'] = (int) 0
    	$f['show_week_number'] = (string) false
    	$f['value'] = <string>
    	$f['required'] = (int) 0
    	$f['type'] = (string) date_time_picker
    	$f['id'] = (string) acf-field-dato
    	$f['key'] = (string) field_51d520b7091da
    	$f['label'] = (string) dato
    	$f['picker'] = (string) slider
    	$f['show_date'] = (string) true
    	$f['order_no'] = (int) 0
    	$f['instructions'] = <string>
    	$f['save_as_timestamp'] = (string) true
    	$f['date_format'] = (string) m/d/y
    $v = (string) 7/11/13 7:00
    $post_id = (int) 6640
    $k = (string) field_51d520b7091da
    $this = Acf[1]
    	$this->settings = array[5]
    		$this->settings['path'] = (string) /Users/per/Sites/dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['dir'] = (string) http://dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['upgrade_version'] = (string) 3.4.1
    		$this->settings['hook'] = (string) advanced-custom-fields/acf.php
    		$this->settings['version'] = (string) 4.1.8
    

    Second iteration, date and timepicker field inside a repeater field

    
    $f = array[16]
    	$f['name'] = (string) repeat
    	$f['class'] = (string) repeater
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[3]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    				$f['conditional_logic']['rules'][0]['value'] = <string>
    		$f['conditional_logic']['status'] = (int) 0
    	$f['layout'] = (string) table
    	$f['row_min'] = (int) 0
    	$f['button_label'] = (string) Add Row
    	$f['sub_fields'] = array[1]
    		$f['sub_fields'][0] = array[18]
    			$f['sub_fields'][0]['label'] = (string) dato2
    			$f['sub_fields'][0]['name'] = (string) dato2
    			$f['sub_fields'][0]['value'] = <string>
    			$f['sub_fields'][0]['key'] = (string) field_51da7b24dbf9a
    			$f['sub_fields'][0]['instructions'] = <string>
    			$f['sub_fields'][0]['save_as_timestamp'] = (string) true
    			$f['sub_fields'][0]['column_width'] = <string>
    			$f['sub_fields'][0]['order_no'] = (int) 0
    			$f['sub_fields'][0]['id'] = (string) acf-field-dato2
    			$f['sub_fields'][0]['picker'] = (string) slider
    			$f['sub_fields'][0]['class'] = (string) date_time_picker
    			$f['sub_fields'][0]['time_format'] = (string) h:mm tt
    			$f['sub_fields'][0]['type'] = (string) date_time_picker
    			$f['sub_fields'][0]['show_week_number'] = (string) false
    			$f['sub_fields'][0]['show_date'] = (string) true
    			$f['sub_fields'][0]['required'] = (int) 0
    			$f['sub_fields'][0]['date_format'] = (string) m/d/y
    			$f['sub_fields'][0]['conditional_logic'] = array[3]
    				$f['sub_fields'][0]['conditional_logic']['status'] = (int) 0
    				$f['sub_fields'][0]['conditional_logic']['rules'] = (int) 0
    				$f['sub_fields'][0]['conditional_logic']['allorany'] = (string) all
    	$f['required'] = (int) 0
    	$f['type'] = (string) repeater
    	$f['id'] = (string) acf-field-repeat
    	$f['key'] = (string) field_51da7b12dbf99
    	$f['label'] = (string) repeat
    	$f['order_no'] = (int) 1
    	$f['instructions'] = <string>
    	$f['row_limit'] = <string>
    $v = array[2]
    	$v['acfcloneindex'] = array[1]
    		$v['acfcloneindex']['field_51da7b24dbf9a'] = <string>
    	$v[1373458984969] = array[1]
    		$v[1373458984969]['field_51da7b24dbf9a'] = (string) 7/12/13 12:00 am
    $post_id = (int) 6640
    $k = (string) field_51da7b12dbf99
    $this = Acf[1]
    	$this->settings = array[5]
    		$this->settings['path'] = (string) /Users/per/Sites/dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['dir'] = (string) http://dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['upgrade_version'] = (string) 3.4.1
    		$this->settings['hook'] = (string) advanced-custom-fields/acf.php
    		$this->settings['version'] = (string) 4.1.8
    
    

    But I guess this is not really the issue. As said previously, the content exist in post meta but it’s not displayed/populated to the custom field.

    When I open a post, where (in ACF) is data read from post meta (ie, where should I set my breakpoints)?

  • In addition to Elliot’s suggested method, if you didn’t want to change the value saved to the database, you could use the DateTime ‘format’ method:

    
    $date = get_field("my_date_field");
    
    // assuming your return format is "Ymd"
    $dateTime = DateTime::createFromFormat("Ymd", $date);
    
    if ( is_object($dateTime) ) {
      $month = $dateTime->format('F');
      $year = $dateTime->format('Y');
      //...
    }
    
  • Ignore my previous question, I can confirm that Date and Time Picker field works fine in ACF v4.1.4

    Thank you dominic 🙂

  • Was it my Date and Time Picker field you tested?

  • I had the same issue with a Date and time picker field. It updates in the database but text input gets emptied after updating a post in the backend. My field is a conditionnal field. I have other fields of the same type innside repeaters and they work fine in 4.1.7… I had to downgrade to version 4.1.4 in order to get it to work and now it’s fine.

  • Hi @madsynn

    You can format the date value into any format you with thanks to the great PHP date / time functions.

    I have written up some code here:
    http://www.advancedcustomfields.com/resources/field-types/date-picker/

    And have extended it a little bit for you below:

    All you need to do is change the format_out and you can do that by finding the format string here:
    http://www.php.net/manual/en/function.date.php

    
    <?php 
    
    /*
    *  Create PHP DateTime object from Date Piker Value
    *  this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)
    */
    
    $format_in = 'Ymd'; // the format your value is saved in (set in the field options)
    $format_out = 'd-m-Y'; // the format you want to end up with
    
    $date = DateTime::createFromFormat($format_in, get_field('date_picker'));
    
    echo $date->format( $format_out );
    
    ?>
    
  • ACF uses a filter called acf/update_value to save the value into the database. I have set it up as a filter so you can hook in and modify the value before save, or use the value in another way.

    Please read the docs about this filter to understand it with more clarity.

    You would hook in using the field name or key, then use the value that was posted to do what ever you want.

    in your case, you would explode the string to get the day, month and year in an array. Then save the month and array to the database using WP save functions

    Is there anything in particular you don’t understand?

  • Been xdebugging, and maybe this helps. core/fields/_functions.php:load_field( $field, $field_key, $post_id = false ) returns:

    $f = array[18]
    	$f['name'] = (string) dato
    	$f['class'] = (string) date_time_picker
    	$f['time_format'] = (string) H:mm
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[2]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    		$f['conditional_logic']['status'] = (int) 0
    	$f['show_week_number'] = (string) false
    	$f['value'] = <string>
    	$f['required'] = (int) 0
    	$f['type'] = (string) date_time_picker
    	$f['id'] = (string) acf-field-dato
    	$f['key'] = (string) field_51d520b7091da
    	$f['label'] = (string) dato
    	$f['picker'] = (string) slider
    	$f['show_date'] = (string) true
    	$f['order_no'] = (int) 0
    	$f['instructions'] = <string>
    	$f['save_as_timestamp'] = (string) true
    	$f['date_format'] = (string) m/d/y

    As you can see, the $f[‘value’] is empty

  • I believe this is the same problem as the one I reported in the old support forum.

    As i mentioned, when I publish the post

    A) update_value() receives the value,

    B) data is stored in “prefix”_postmeta table:

    select * from dev_postmeta where meta_key = 'dato' ORDER BY meta_id DESC LIMIT 1;

    returns the correct value in meta_value (‘dato’ is the field name)

    select * from dev_postmeta where meta_key = '_dato' ORDER BY meta_id DESC LIMIT 1;

    returns the correct field_”number” in meta_value

    C) create_field() creates an empty field on reload after the publish post

  • Can you explain with an example Please

  • Hi @biomedikal

    Perhaps you could use the update_value filter to run a custom save function.

    The update_value filter is run on every value you save with ACF. It’s native functionality is to save the value to the database, however, you can hook in and do what ever you want.

    Jump over to the docs and check out the filter. You will be able to look at the value saving, and extract the month / year (with an explode function) and then use the native update_postmeta function to save the value to the post!

    Good luck

Viewing 12 results - 776 through 787 (of 787 total)