Support

Account

Home Forums Search Search Results for 'date picker'

Search Results for 'date picker'

reply

  • John,
    Thanks for your response.

    Basically, I have a date-picker custom field that should update the post title and post slug on update. It was working fine but the formatting was off–always displaying the date as YYYYMMDD.

    I later got the formatting to work, but it created another problem—the date isn’t being saved the first time around and therefore the need to update twice.

    This issue is beyond me. I hope that clarifies.

  • hi, i think something like that should work

    add_filter('acf/load_value/name=repeater_termin', 'my_acf_load_value', 10, 3); //repeater_name
    function my_acf_load_value( $rows)
    {
     foreach( $rows as $key => $row ) {
      $thedate = $row['termin_date']; //datepicker_fieldname
      $column_id[ $key ] = strtotime($thedate);
     }
     array_multisort( $column_id, SORT_ASC, $rows );
     return $rows;
    }
  • Hi @cannon303

    Hmm.. ACF uses the builtin datepicker in WordPress which is Iris by Automattic.: http://automattic.github.io/Iris/

    There’s the palette option which you could use. However (I just noticed this) there is no filter hook for the color pickers options. I’m going to make a feature request for this in the development github repo.. Hopefully Elliot will add this in pretty fast.

    In the meantime the only thing I can think of is to reinitialize the colorpicker yourself with a custom script in wp admin.
    You can use this snippet for adding inline javascript:

    
    function my_acf_input_admin_footer() {
    	
    ?>
    <script type="text/javascript">
    (function($) {
    	
    	// JS here
    	
    })(jQuery);	
    </script>
    <?php
    		
    }
    
    add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
    
  • I got stuck on this today, and all of these solutions seems a little overkill to me. I came up with this, which seems to be working fine for me. I’ve got mine pulling in the palettes from an options page, but the general idea should still be clear.

    function acf_iris_palette(){
      $palette = json_encode( array_column( get_field('palette', 'options'), 'colour' ) );
      ?>
    	<script type="text/javascript">
        jQuery(function($){
          var acfColourPicker = $('[data-type="color_picker"] input[type="text"]');
          if ( acfColourPicker.length )
            acfColourPicker.iris('option', 'palettes', <?php echo $palette; ?>);
        });
    	</script>
      <?php
    }
    add_action( 'admin_print_scripts', 'acf_iris_palette', 90 );
    

    Hope that helps somebody 🙂

    Edit: Apologies, I realise this doesn’t work on repeater fields or other dynamically generated fields. I’ll update this when I fix it.

  • Thanks for reply, I dropped it but now I have to resolve the issue.
    Basically I have a date picker custom field where user picks the event date when creating new post. I display all posts on a page and I order them by this event date. What I need is a filter option above the posts where you can pick the month to see only the events happening that month.

  • Hi @romanzmykulova

    As the datepicker that’s currently available stores the date in Ymd format (which is the best for any sort of date manipulation I think) I’m guessing a datetime picker would store the value as a datetime string (19700101T00:00:00).

    It can be very easily formatted with the date function as well as other functions so it should be fine!

  • Hello, pardon me for returning to this old post, i have a similar need, and the code does work, but ordering is not. i’m trying to order by the datepicker value, but posts are ordering by the most recent publish, not the datepicker. I’m using custom post.
    For example, if i publish a new post for 2011 in the datepicker, the year 2011 goes to top, so i have something like: 2011… 2015…2013… 2010… 2014.
    Any clues?

  • If the fields are not part of a repeater or some special field type, for example the date fields are just date pickers, number fields are just numbers, there are no checkboxes or multiselect fields that store data in serialized arrays, then you are just sorting by multiple postmeta fields.

    There was a new feature added to WP in 4.2 that allows you to do this. I don’t know if it’s made it into the documentation. This page explains it. https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

    And like I said, you need to modify the main query to change the order. This is done using pre_get_posts https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    Here is a posts on stack exchange that shows how to use pre_get_posts an order the posts by a single meta value http://wordpress.stackexchange.com/questions/141355/wordpress-screwing-up-orderby-meta-value-num-in-pre-get-posts

  • I’m a little late to this party but I was at my wits’ end figuring this out and managed to nail it.

    I have a custom taxonomy called issue which has a custom field issue_date (date picker field). I wanted to add a custom column in the taxonomy edit screen to sort my issues by their dates. Here is what I came up with:

    Step 1: Add the new Date column

    function issue_columns($issue_columns) {
      $issue_columns['date'] = 'Date';
      return $issue_columns;
    }
    add_filter('manage_edit-issue_columns', 'issue_columns');

    Step 2: Populate the new Date column

    function manage_issue_columns($out, $column_name, $term_id) {
      $issue = get_term($term_id, 'issue');
      $date = DateTime::createFromFormat('Ymd', get_field('issue_date', $issue));
      switch($column_name) {
        case 'date': 
          $out = $date->format('Y/m/d');
        break;
        default:
        break;
      }
      return $out;    
    }
    add_filter('manage_issue_custom_column', 'manage_issue_columns', 10, 3);

    Step 3: Make the new Date column sortable

    function my_sortable_issue_column($columns) {
      $columns['date'] = 'issue_date';
      return $columns;
    }
    add_filter('manage_edit-issue_sortable_columns', 'my_sortable_issue_column');

    Step 4: Define the custom sorting (where the magic happens)

    function sort_issues_by_date_column($pieces, $tax, $args) {
      global $pagenow;
      if(!is_admin()) {
        return;
      }
    
      if(is_admin() && $pagenow == 'edit-tags.php' && $tax[0] == 'issue' && (!isset($_GET['orderby']) || $_GET['orderby'] == 'issue_date')) {
        $pieces['join']   .= " INNER JOIN wp_options AS opt ON opt.option_name = concat('issue_',t.term_id,'_issue_date')";
        $pieces['orderby'] = "ORDER BY opt.option_value";
        $pieces['order']   = isset($_GET['order']) ? $_GET['order'] : "DESC";
      }
    
      return $pieces;
    }
    add_filter('terms_clauses', 'sort_issues_by_date_column', 10, 3);

    For reference, my date picker field setting returns the date in the format Ymd.

    If anyone has any improvements or questions please let me know!

  • Please, can we change the behavior of the page link to be more like the native WP link selector? There was a plug in that did this brilliantly:

    https://wordpress.org/plugins/advanced-custom-fields-link-picker-field/

    Unfortunately, it broke during an update and hasn’t been fixed (not counting on the fork someone made). Depending on a plugin for this type of functionality puts me (us) in a position where clients will become upset when their site breaks because of a ACF or WP update. Please add this to the core page link.

    Appreciate it!

    [Edit]I just want to point out the initial request was made in 2013. We are 75% through 2015…[/Edit]

  • Great to hear, this will be a really useful addition. When using the date picker to organise posts such as listing events by a start date, having the option to choose a time will mean we can use that date + time in our query to even organise events happening on the same day correct?

    i.e. if three events are happening on the same day, I could order them by the date + time so they’re in the right chronological order right? When you guys implement that, it would be amazing if you could update this guide on your site to show how to do that:

    http://www.advancedcustomfields.com/resources/date-picker/

    Thanks for creating and maintaining this plugin Elliot, Jonathan and the team, you really are all a life saver.

  • Hi @ch1n3s3b0y

    The date picker in ACF does not support time at all so I’m assuming you’re using a custom third party addon for that. Possibly this: https://wordpress.org/plugins/acf-field-date-time-picker/ ?

    If so I suggest you post your question in that support forum instead since we can’t provide help for third party solutions 🙂

    There are talk of adding a datetime field in ACF core at some point but we’re not there yet.

  • Hi @acf2015

    Nice username btw 😉

    Have you made sure that your script are being loaded?
    The unique ID is not the field name tho. I believe it’s usually the field key (unless the field is a subfield). You can find the field key by ticking “show field keys” in the admin area of your field groups “screen options”. You can also make sure you got it right by looking at the source code of the datepicker HTML.. easiest is to use chromes inspector or maybe Firebug in firefox.

  • Hi @yarongo

    The datepicker uses jquery UI datepicker and you can update the minDate and/or maxDate values like this:

    
    //This is an example field key. You need to use your own
    jQuery( '.acf-field-54cfe68700b24 .acf-date_picker input.input' ).datepicker( 'option', 'minDate', date.format() );
    

    so if you target a change in the first datepicker, find out the value set and use it to set the minDate with the above code it should work. I’ve done something similar before myself 🙂

  • Hi @dinohajric

    I think ACF uses the jquery UI datepicker (if I’m not mistaken). Do you know if that supports Hijri at all?

  • Well I finally solved it by changing the store format to yymmdd. After that I could use the code example from the documentation like this.

    $date = DateTime::createFromFormat('Ymd', get_field('date_picker'));
    echo $date->format('d-m-Y');

    I changed the output value to j F Y but then found out that the output was English even though it was displayed in Dutch in the WP admin area. But well that was easily sorted with the translation snipper from the documentation.

    <?php
    
    $dateformatstring = "l d F, Y";
    $unixtimestamp = strtotime(get_field('date_picker'));
    
    echo date_i18n($dateformatstring, $unixtimestamp);
    
    ?>

    So in the end I didn’t even have to use my code that was causing the error and was making it too complicated for myself when I could use the code examples. But well, I learned something again as this was my first usage of the date picker field.

  • Yes, exactly that is my goal. But how can i “inject” values from custom field(php) to javascript?

    I can disable dates manually by editing datepicker script, but the problems is to getting it work with dynamic editing.

  • I think I got it, or at least it is working now. I changed into the datepicker field options from 14/09/2915 to d/m/Y (I wrote it manually, I don’t know why selecting the 14/09/2015 option didn’t work).

    And now using this code is working fine:

    <div class="col-sm-3">
    
    			<?php 
    			if(get_field('fecha_del_evento'))
    			{
    				$datetime = DateTime::createFromFormat('d/m/Y', get_field('fecha_del_evento'));
    				$fecha_dia = $datetime->format('d');
    				$fecha_mes = $datetime->format('M');
    			}            
    			?>
    			<div class="eventos row">
    				<div class="col-xs-3">
    					<div class="fecha">
    						<p class="mes"><?php echo $fecha_mes; ?></p>
    						<p class="dia"><?php echo $fecha_dia; ?></p>
    					</div>
    				</div>
    				<div class="col-xs-9">
    					<?php the_content (); ?>
    				</div>
    			</div>
    		</div>
  • Hi @pagol

    You need to check out the orderby parameter of wp_query.
    I haven’t tested this code and you might need to set the order parameter to either ASC or DESC as well. But give it a go:

    
    <?php 
    $args = array(
    	'cat' => 'event',
    	'posts_per_page' => 2,
    	'orderby' => 'meta_value',
    	'meta_type' => 'DATE',
    	'meta_key' => 'fieldnameofdatepicker'
    	
    );
    $news = new WP_Query($args); 
    ?>
    <?php while ($news->have_posts()) : $news->the_post(); ?>
    	<li>
    		<h3><?php the_field('date'); ?></h3>
    		<h4><?php the_title(); ?></h4>
    	</li>
    <?php endwhile; ?>
    
  • Hi @djjoshdavid

    You should be able to change the display format of the date picker off the bat from the field settings edit screen.

    Are there any errors that you can report that are appearing on the console?

    It is also possible to make use of the PHP date() function to change the format of the date. You can check this out here http://php.net/manual/en/function.date.php

  • Hi @phoenix-systems

    Thank you for the question.

    This is certainly not a common issue, it may be possible that there is a plugin/ theme conflict that is interfering with the saving of values in the date picker field.

    I would recommend you try to investigate by deactivating all other installed plugins and switching to one of the stock WP themes to check if the issue will be replicated.

  • Hi @hejamartin

    This is actually a topic we’re discussing on the Github repo and there are plans to include either time selection in the existing date picker field or as a separate field.

    So you should expect it to show up in a not too distance future update 🙂

  • Hi,

    Sorry for the unclear description. So I have installed AFC plugin and created a custom field from type datepicker. I assigned this field to posts. I have custom new post form which users with specific permissions can submit when they login. The custom field currently is available only for the admins who create new post from the WP admin panel. I want to make the custom field available in my front end submit new post page too. Is there any way to attach the custom field as additional field into my current form ? I hope this make sense.

    Regards

  • Hi @cliffordp

    Thank you for the feedback! ACF is almost entirely maintained by Elliot Condon alone and as such he has quite a lot to do!

    I can imagine that the date picker could be extended to also include time and timezones but I don’t think it can be given a high priority. There’s also the possibility to create your own field type for this like in the link you sent.

    I will create a feature request for this but I can’t say when or if it’ll be implemented. Perhaps I give it a go myself at some point as I do think it’s a good extension if done right!

  • Hi,

    Yes this is absolutely possible and it’s not even validation. It’s more about limiting the datepickers depending on each other..

    I’ve done exactly this myself but on a front end ACF form so I’m certain it works.
    Good luck!

Viewing 25 results - 526 through 550 (of 784 total)