Support

Account

Home Forums Search Search Results for 'date picker'

Search Results for 'date picker'

reply

  • The date_end is one of the fields in the group.
    I think that the problem is the Save Format: dd/MM/yy, because if I create a new Custom field and I set Return Format: Ymd, then the code is working and the products are ordered correctly. I can’t change the save format of my custom field because I have many functions that are using it and If I change it, the site will break.
    How can I convert this in the query, so that this works?
    Also, this field is old (before update of acf plugin), and now I see that If I create a new field Date Picker, the options are different ( instead of Save Format, there is Return Format etc). Right now I’m using version 5.11.4.
    I’m really confused.
    Thanks.

  • The date_end is one of the fields in the group.
    I think that the problem is the Save Format: dd/MM/yy, because if I create a new Custom field and I set Return Format: Ymd, then the code is working and the products are ordered correctly. I can’t change the save format of my custom field because I have many functions that are using it and If I change it, the site will break.
    How can I convert this in the query, so that this works?
    Also, this field is old (before update of acf plugin), and now I see that If I create a new field Date Picker, the options are different ( instead of Save Format, there is Return Format etc).
    I’m really confused.
    Thanks.

  • I’m facing a similar challenge and I’m wondering if you ever found a solution.

    My scenario:

    1. Options page #1: an ACTIVE repeater with the following fields
      • Product (text)
      • Date in (datepicker)
      • Date out (datepicker)
    2. Options page #2: a duplicate from [1] named ARCHIVE

    ARCHIVE has the exact same fields as above.

    After field [Date out] reaches a certain date, I want that specific row to be moved (or copied) from the ACTIVE to the ARCHIVE.

    Hope I make sense.

    Thanks in advance!

  • Hello,

    In order to use the time picker you need to add few php functions at your page, after the block/slider is loaded. Declare and get today’s date, get start and end date of the picker and set an if statement to check whether or not todays date match between the pre-set interval in the back-end.

  • My previous solution has the unwanted effect that it overwrites already set dates that are in the past to the current day.

    Correct solution came from https://stackoverflow.com/questions/62204645/disable-dates-and-days-of-the-week-in-acf-date-picker

    
    acf.add_filter('date_picker_args', function( args, $field ){
      args['minDate'] = '0';
      return args;
    });
    
    
  • For other users looking for this answer, the current syntax is a bit different:

    
    // Don't allow picking dates in the future
    acf.addAction('date_picker_init', function( $input, args, field ){
      $input.datepicker('option', 'maxDate', 0);
    });
    
  • Worth looking at this forum post it may help you

  • Does this post do what you need?

    Once you query but what you need, you can then do something like:

     $the_query = new WP_Query( $args );
      $totalposts = $the_query->found_posts;
    echo $totalposts; 

    Code untested and will need adjusting to fit your field names etc. but should get you underway!

  • Here the ACF field group

    [
        {
            "key": "group_6188d209a6110",
            "title": "Events CPT Fields",
            "fields": [
                {
                    "key": "field_6188d22182ad0",
                    "label": "Event Date",
                    "name": "event_date",
                    "type": "date_picker",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "display_format": "F j, Y",
                    "return_format": "F j, Y",
                    "first_day": 1
                },
                {
                    "key": "field_6188d25582ad1",
                    "label": "Date and Time",
                    "name": "date_and_time",
                    "type": "date_time_picker",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "display_format": "F j, Y \\@ g:i a",
                    "return_format": "F j, Y \\@ g:i a",
                    "first_day": 1
                },
                {
                    "key": "field_6188d27582ad2",
                    "label": "Event Location",
                    "name": "event_location",
                    "type": "text",
                    "instructions": "Add the event location here",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "placeholder": "",
                    "prepend": "",
                    "append": "",
                    "maxlength": ""
                }
            ],
            "location": [
                [
                    {
                        "param": "post_type",
                        "operator": "==",
                        "value": "event"
                    }
                ]
            ],
            "menu_order": 0,
            "position": "normal",
            "style": "default",
            "label_placement": "top",
            "instruction_placement": "label",
            "hide_on_screen": "",
            "active": true,
            "description": ""
        }
    ]
  • Hello
    Help me please
    I used wp_insert_post to create new post in cpt
    what needs to be sent to the field “meta_input” add to Data Picker in ACF?
    when I send in data (ex 2029) POST all right – https://prnt.sc/1x73dvk
    but in new post acf field (Data Picker) only 1970 – https://prnt.sc/1x72yu8
    for other fields all ok

    My code like this

    $advert_name = $_POST[‘advert_name’];
    $advert_rent_date = $_POST[‘advert_rent_date’];
    
    $advert_new = [
    ‘ID’ => ”,
    ‘post_type’ => ‘offers’,
    ‘meta_input’ => [
    ‘name’ => $advert_name,
    
    ‘date’ => $advert_rent_date
    ],
    ‘post_content’ => $advert_desc,
    ‘post_title’ => $advert_title,
    ‘post_status’ => ‘pending’
    ];
    
    $post_id = wp_insert_post($advert_new);
  • To automatically set the end date when the start date is changed you would need to build custom javascript, here is an example: https://www.damiencarbery.com/2020/06/acf-date-picker-set-end-date-to-after-start-date/

    To require it to be after the start date you need to use an acf/validate_value filter, there is an example of this here https://support.advancedcustomfields.com/forums/topic/how-to-use-acf-datepicker-for-start-date-less-than-end-date-validation/

  • Thank you, the acf_update_setting mentioned in that thread was a help,

    With acf_update_setting I was able to get rid of select2, datepicker, timepicker

    Then after much searching and help from Query Monitor, I was able to get the handles and figure out alot of the others need to be dequeued through init hook, so through that I was able to get rid of jq touch punch, iris, wp-color-picker and code-editor.

    Through the init you can also get rid of jq ui core, jq ui mouse, jq ui sortable & jq ui resizable – unfortuneatly due to how they are all dependencies of each other and other scripts are dependencies/dependants of them, they seem to end up causing errors and breaking things with the main acf js object.

    Would be great if there was a way for these not all to be so intertwined however I understand why its like this, it just makes simple text field based forms somewhat pointless in acf_form when compared to other options.

    FYI for anyone in the future: I did have to also deregister & dequeue

  • Thanks… the specific issue with the date picker is that previously it would always be positioned entirely above or below the input; now if that would cause it to run off the screen, it shifts enough so that it doesn’t run off the screen at all… but that results in it covering the input. I was able to work around it by just modifying the page layout so the form starts a bit lower on the page. (This is something I’m only using for personal use right now so the design is not critical.)

    As for the second issue… I agree that it’s odd that it ever worked. But it did, and now it doesn’t, so I’m trying to figure out what happened.

  • just an update for anyone else:

    hi. just wanted to update you on the solution, which i found with help of Oxy Support. firstly, it IS a bug, and it’s been reported to the devs. it’s specific to Repeaters, because in testing i first rebuilt the whole site in Italian, but same issue; the ACF datepicker inside a Repeater refused to be anything but in English. the solution (in case anyone asks you) is to use a Code Block instead of Dynamic Data in a text Block. in the Code block (if the ACF datepicker field is ‘single_event_date’, and desired format is d F Y) is:

    $date_string =strtotime(get_field('single_event_date'));
                
        $formatted_date = date_i18n('d F Y',$date_string);
    
        echo $formatted_date;
  • but to update, when i change the datepicker Display and Return format to ‘Ymd’ from what i had, which was a Custom ‘d F Y’ then that does solve the 500 errors and the broekn front end pages. site is Italian. Me as admin user is also Italian (site default) so i have a basic translation issue, but no idea why.

  • hi.

    beacause: pages without ACF content load fine, switching back the English as Site Language solves the issue, and leaving Site Language in Italian but disabling ACF works fine. also spun up another site, switched site language first, then installed ACF and added a Date Picker and that works too. so it’s building in ACF, then switching Site language that’s the problem. No error logs, but building on a Synology Diskstation and they hide them, which is unfortunate.

    i don’t actually care what the Site Language is, and it’s not a multilingual site and no language switching. the whole thing front end is Italian content, and all ACF field content too. it’s just the Date picker, the written months in format F or M (Jan or Janaury, Feb or Febraury etc, changed to Gen and Gennaio, Feb and Febbraio etc), that i need to string replace. even a translation plugin seems unnecessary, but i’m totally stuck. hope you can help!

  • Hey, that looks great!!!
    The only thing is, that in the date picker field there is always the date “01.01.1970” , but in the custom field it saves the correct date. https://imgur.com/a/JXIIybQ

  • There is a filter for the date time picker arguments. I don’t have any example of making this change but it should allow you to set the timezone based on the user. I also to not know how this will effect how ACF saves the value.

  • Agree 100%.

    I did not test it yet, but I guess we have to code a function for it…

    https://support.advancedcustomfields.com/forums/topic/default-value-for-datepicker/

  • @hatsumatsu ‘s solution works great, except I can’t seem to be able to make it work with a date field assigned to a custom taxonomy. I’m using it for a date picker like this:

    /**
     * Convert values of ACF core date pickers from Ymd to timestamp
     * @param  string $value   unmodified value
     * @param  int    $post_id post ID
     * @param  object $field   field object
     * @return string          modified value
     */
    function acf_save_as_wp_date( $value, $post_id, $field  ) {
        if( $value ) {
            $value = strtotime( $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/update_value/type=date_picker', 'acf_save_as_wp_date', 10, 3 );
    
    /**
     * Convert values of ACF core date pickers from timestamp to Ymd
     * @param  string $value   unmodified value
     * @param  int    $post_id post ID
     * @param  object $field   field object
     * @return string          modified value
     */
    function acf_load_as_acf_date( $value, $post_id, $field  ) {
        if( $value ) {
            $value = date( 'Ymd', $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/load_value/type=date_picker', 'acf_load_as_acf_date', 10, 3 );

    Tried adding the name of taxonomy, like $value = strtotime( $value, 'event_dates' ); and $value = date( 'Ymd', $value, 'event_dates' ); as well, but I don’t know if that’s at all correct way of doing it.

  • Thanks again John. What really annoys me is the developers have created this fantastic plugin, then gone further and added a javascript library which adds another level of sophistication, but then seem to ignore customers that want to make use of it.

    I’ve worked for 40+ yeas in IT development. support and consulting, and I understand it’s difficult, but we never released a toolset then didn’t give our customers documentation or support for it.

    Anyway, enough a a rant. I have a field group as follows;
    Picture – image
    Location – text
    Date – datepicker
    People – Repeater
    –Person – relationship
    –coord_left – number
    –coordtop – number
    –coordright – number
    –coordbottom – number

    I load the image and run a js using Clarifai’s face recognition engine. It returns boxes around each face in the picture and a list of coords of these boxes.

    I want to populate the repeater field with the ID of a unknown person (from the people field group) and he coords from above. The user will then change the person from the unknown person to one from the field group and save the post.

    I have the recognition working and the trigger click firing the code from the acf.addaction append code you pointed me at. I’m trying now to add the ID and coord fields with the data from the face recognition.

    I was hoping I could have something to loop through the faces I have, triggering the new row, then adding the 5 fields. Although this should work, it’s a bit messy.
    I would have hoped there was a add.row function that I could call to add my rows before displaying them, rather than acting like keyboard input and relying on the users to save the updates.

    I find it very difficult to identify the field names as on the page they seem to be part of a hierarchy which I cannot find a description for (e.g. id=”acf-field_609af70f9fdac-acfcloneindex-field_609af86f9fdb1″ name=”acf[field_609af70f9fdac][acfcloneindex][field_609af86f9fdb1] where the field ending in db1 corresponds to one of the coordinate fields I defined). This makes the coding more difficult.

    I hope I’ve not gone on too much, but thanks for your help anyway.
    row
    #

  • @hube2 I appreciate any help you can provide and totally understand your position regarding your framework and all the work that has gone into it.

    I have an “event” custom post type with the date picker field included. I’m using the following code in a page template to pull in the current month’s events, which is working fine. But I have no clue how to get this to paginate from month to month. What is needed is for the user to arrive on the page showing the current month’s events, then be able to click through to the next month’s events, and so on, including clicking back to the previous month but not past the current month. My guess is that I need to use WP_Query instead of get_posts, but still not sure how to get that to work.

    Again, any help you can provide is greatly appreciated!

    <?php
            $year = date('Y');
            $month = date('m');
            $posts = get_posts(array(
                'post_type' => 'event',
                'posts_per_page' => -1,
                'order' => 'ASC',
                'orderby' => 'meta_value',
                'meta_key' => 'date',
                'meta_query' => array(
                    'relation' => 'AND',
                    array(
                        'key' => 'date',
                        'value' => $year.''.$month.'01',
                        'compare' => '>=',
                    ),
                    array(
                        'key' => 'date',
                        'value' => $year.''.$month.'31',
                        'compare' => '<=',
                    )       
                )
            ));
            if( $posts ) : foreach( $posts as $p ) :
            $date_string = get_field('date', $p->ID);
            $date = DateTime::createFromFormat('Ymd', $date_string);         
            endforeach;
            ?>
            <div class="small-12 columns text-center">
                <h2><?php echo $date->format('F Y'); ?></h2>
            </div>
            <?php
            foreach( $posts as $p ) :
            $background_color = get_field('background_color', $p->ID);
                if($background_color == 'terracotta') {
                    $bkg = '#AD7A67';
                } elseif($background_color == 'sand') {
                    $bkg = '#C3AD93';
                } elseif($background_color == 'dark-blue') {
                    $bkg = '#2D4B62';
                } elseif($background_color == 'seafoam-green') {
                    $bkg = '#91ACA9';
                }
            $date_string = get_field('date', $p->ID); 
            $date = DateTime::createFromFormat('Ymd', $date_string);
            $name = get_the_title($p->ID);
            $start_time = get_field('start_time', $p->ID);
            $description = get_field('description', $p->ID);
            $event_page_link = get_field('event_page_link', $p->ID);
            $register_link = get_field('register_link', $p->ID);
            ?>
            <div class="large-3 small-12 columns">
                <div class="event section--one__content__event" <?php echo 'style="background-color:'.$bkg.';"'; ?>>
                    <?php
                    if($date) echo '<div class="name section--one__content__event__day">'.$date->format('j').'</div>';
                    if($name) echo '<div class="name section--one__content__event__name">'.$name.'</div>';
                    if($start_time) echo '<div class="name section--one__content__event__time">'.$start_time.'</div>';
                    if($description) echo '<div class="position section--one__content__event__description">'.$description.'</div>';
                    if($event_page_link) echo '<a href="'.$event_page_link.'" target="_blank" class="link section--one__content__event__link">EVENT PAGE</a>'; 
                    if($event_page_link && $register_link) echo ' <span class="link section--one__content__event__link">|</span> ';
                    if($register_link) echo '<a href="'.$register_link.'" target="_blank" class="link section--one__content__event__link">REGISTER</a>';
                    ?>
                </div>
            </div>
            <?php 
            endforeach; 
            
            endif; 
            ?>
    
  • Hi, can someone explain how this works? I’m using code from @lsterling03 , but it doesn’t works for me. I can share my date-picker field settings, if needed…

  • I think the same in this case,

    We should be able to remove any script if we really don’t need them, if don’t have date-picker field I don’t know why is loaded datepicker.min.js.

    This make a huge deference in page speed result pages.

Viewing 25 results - 176 through 200 (of 784 total)