Support

Account

Home Forums Search Search Results for 'date picker'

Search Results for 'date picker'

topic

  • Solved

    Unable to set post status to future when setting future date via ACF field

    Hi all, I’ve been struggling with this for days now.

    So I’m setting the post date of a custom post type based on an acf field, the dates will alway be in the future so I want the post to be “scheduled”. While the date does get properly set to the future https://share.getcloudapp.com/yAu9ylvN it’s still set at published even though I’m attempting to set post status to “future” it doesn’t do so. If I manually change the date in the WP date time picker the “update” button changes to a “Schedule” button and it works properly but for some reason setting it from an acf field doesn’t allow one to also set the post status to future. Code below.

    
    add_action("acf/save_post", "test_update_post_date_from_acf");
    function test_update_post_date_from_acf($post_id)
    {
      $post_date = get_field("start_date");
      $post = wp_update_post([
        "ID" => $post_id,
        "post_date" => $post_date,
        "post_status" => "future",
      ]);
    }
    
  • Helping

    Date front end display format

    I’m struggling to convert an ACF date picker field to be displayed in the correct format on the front end.

    I’m using this snippet to display the 2 product custom fields on the order confirmation and the associated email.

    add_action( 'woocommerce_order_item_meta_start', 'order_item_meta_start', 10, 4 );
    function order_item_meta_start($item_id, $item, $order, $plain_text) {
    	$the_order_id = $order->get_id();
    	$order_items = $order->get_items();
    	$custom_field_variable1 = get_post_meta( $item->get_product_id(), 'competition_reference', true ); // Change custom_field_name to the name of your custom product meta field
    	$custom_field_variable2 = get_post_meta( $item->get_product_id(), 'competition_draw_date', true ); // Change custom_field_name to the name of your custom product meta field
    	echo '<p>Competition Reference: ' . $custom_field_variable1 . '<br>Competition Draw Date: ' . $custom_field_variable2 . '</p>';
    }

    It works in the fact it displayed the ACF data, but it displays the date as YYYYMMDD rather than my ACF return format of dd/mm/YYYY

    Product
    LEGO® Star Wars™ Darth Vader Helmet (75304)
    Competition Reference: LegoDV_001
    Competition Draw Date: 20230630

    How can I return the date correctly?

  • Solving

    Shortcode of datepicker within repeater field

    Is there a shortcode to output the date selected in the date picker subfield?

    The output format should be ‘d F Y’

    My repeater field is called course_dates
    My date picker subfield is called start_date

    Someone can help me out?

  • Solved

    Nested repeater and programmatically add values

    Hello all.

    I use ACF Pro and I’ve created a nested repeater field for working hours in a CPT.

    The structure is like that:

    Repeater Field [Field Name: working_hours] (Working Days) (To repeat the week days and working hours of the days)
    Select [Field Name: day] (contains the names of the week days)
    Repeater Field [Field Name: working_hours] (Working Hours repeater to add the working hours per day)
    Time Picker [Field Name: from] (From time)
    Time Picker [Field Name: to] (From time)

    Now, what I need to achieve is to populate the fields with data programmatically.

    What I have try so far is to use the update_field and a structure like this as value:


    $options = [
    "working_hours" => [
    [
    "day" => "Monday",
    "working_hours" => [
    [
    "from" => "09:00",
    "to" => "14:30",
    ],
    [
    "from" => "17:00",
    "to" => "20:30",
    ]
    ]
    ],
    // ... other days here
    ]
    ];

    But this creating only the top level of repeated elements and the child fields are all empty.

    For example, if I have a seven days values (first working_hours contains seven child arrays) in the post I get seven repeated items, all showing Monday and no registered hours.

    Can someone show me how can I achieve this programmatically?

    Thank you in advance !

  • Solving

    Date time picker not working

    WP version : 6.2.2
    ACF version : 6.1.6
    CPT version: 1.13.4
    I am having custom post type in my site in that i have added two ACF fields which are of type Date Time Picker. If i entered some value by choosing date and time and save, the values are cleared. It is not saving. Same for time picker field.

    https://tinyurl.com/2poyefzh

  • Solving

    return format date picker problem

    Hello fellow acf users,

    I have set the return format of the date picker to F, Y. I am using the search & filter plugin and it displays it in the filter form as (20230303).

    Even if I set the display and return format to F, Y, it still doesn’t work. Does anyone know how i can solve this?

    thanks in advance for your help!

  • Unread

    ACF Date Picker Data To Gravity Forms Date Field

    Hi all,

    I have a date field created using an ACF date picker which is set up as user meta for date of birth.

    Using the Gravity Forms User Registration add-on/update user, I’m trying to auto populate a gravity form date field with the corresponding dd/mm/yyyy data. Is there a way to do this using something like {user:date_of_birth:dd} {user:date_of_birth:mm} {user:date_of_birth:yyyy} or something like that?

    We need to allow users to view and edit their date of birth in case it was originally entered incorrectly.

    Thanks

  • Solved

    Ninja Forms and ACF Date/Time Picker Not Behaving

    I’ve got a Ninja Form with a Date/Time Picker. I am using update_field to save the value in the database, but it will not work correctly and instead saves the value as:

    a:4:{s:4:"date";s:10:"2023-03-07";s:4:"hour";s:2:"04";s:6:"minute";s:2:"30";s:4:"ampm";s:2:"pm";}

    This breaks the database record since this is not a properly formatted Date/Time – which should be converted to YYYY-MM-DD HH:II:SS in the database by update_field

    What’s weird to me, is that if it’s a Date picker only, the update_field function works just fine. So it appears the issue is with the Time part.

    It’s infuriating.

  • Unread

    ACF Date and Time Format Differs When Used in List Category Posts Shortcode

    The date (j F Y) and time (H:i) format set in ACF differs when we use it in the “List category posts” shortcode.

    In the ACF (custom fields) plugin it’s set to the above mentioned, which works fine when using [acf field="webinar_date"] in example. Whenever we try to implement it the List Categor Posts shortcode, the date displays as YYYYMMDD (20230316 instead of 16 March 2023) and the time as HH:MM:SS (16:00:00 instead of just 16:00).

    The List Category Posts shortcode used, is as follows:
    [catlist excerpt=yes excerpt_size=20 id=91 pagination=yes numberposts=10 posts_morelink=”Register” customfield_display=”yes” customfield_display=”webinar_date,webinar_sast_start_time,webinar_sast_end_time,webinar_est_start_time,webinar_est_end_time” customfield_display_name=”no” customfield_display_separately=”yes”]

    Is there any way to fix this? We have tried numerous suggestions found online. The last solution we tried, is by including the below mentioned code in the functions.php file (via the Code Snippet plugin):
    function acf_smart_dates($field) {
    if ($field[‘webinar_date’]) {
    $field[‘webinar_date’] = date(‘dmY’,strtotime($field[‘webinar_date’]));
    }
    return $field;
    }
    add_filter(‘acf/prepare_field/type=date_picker’,’acf_smart_dates’);

    Thank you in advance for any suggestions.

  • Helping

    Is there a way to set a default value for a timepicker field?

    The title pretty much says it all.

    I have a timepicker field (start_time) that’s optional and only appears if someone has set a value on a datepicker field (start_date).

    I need to sort posts by start_date, and – if there is a value for the start_time field – sort by start_time within the posts for the start_date.

    I don’t see a way to set a default value for start_time when setting up the ACF.

    If there’s not a way to do it within the admin interface, is there a way to do it when retrieving the post meta data?

  • Helping

    Age calculation ouput

    I have a date of birth field and I need to learn how to create a way to calculate the persons age and display it in a post.

    I would imagine have the date of birth date picker field is obvious, but to I need to create another field like “age” where the calculated age can be output?

    Thank you for any suggestions

  • Helping

    Sort posts in a widget using 2 ACFs

    I have a field group for standard WP posts that includes among others) the following optional ACFs:

    • start_date – set using the Date Picker
    • start_time – set using the Time Picker; only available if start_date has a value

    To be clear: not all the posts that have start_date value also have a start_time value.

    I have custom widget that only displays posts that have a start_date value that’s (1) today or later, and (2) that’s within the next N days, where N is set in the widget admin interface. The posts are sorted by start_date in ascending order.

    That part all works just fine. Where I’m having trouble is being able to include the optional start_time ACF in the sort order so that posts would be listed like this:

    February 23
    February 24 10:00am
    February 26
    March 5 8:00am
    March 5 10:00am
    March 6

    This is the $args array that sorts (correctly) only by start_date:

        $args = array(
          'ignore_sticky_posts'=> 0,
          'post_type' => 'post',
          'post_status' => 'publish',
            'meta_query' => array(
              array(
                'key' => 'start_date', // ACF field for event start date
                'value' => date('Ymd', strtotime("+{$nr_days_ahead} days")), // restrict start date to no more than today + $nr_days_ahead
                'compare' => '<=',
                'type' => 'DATE'
              ),
              array(
                'key' => 'start_date', // ACF field for event start date
                'value' => $today,
                'compare' => '>=',
                'type' => 'DATE'
                )
              ),
          'posts_per_page' => $nr_posts,
          'cat' => $categories,
          'meta_key' => 'start_date',
          'orderby' => 'meta_value_num',
          'order' => 'ASC'
        );
    

    I spent quite a bit of time today with ChatGPT (just in case anyone feels like suggesting that approach), but never got anywhere (other than a couple critical errors that brought the site down, but I can manage that all by myself).

    Any suggestions?

  • Unread

    Custom query order by …

    Hello,

    i need your help plz 🙂

    I have this ACF fields :

    – type (checkbox type)
    – date with datepicker

    I have to order all my post with type = “mytype” (can we use ID ?) and order by date DESC

    How can i do this plz ?

    Thanks a lot.

    i did it :

    $prez = get_posts(array(
    ‘post_type’ => ‘myposttype’,
    ‘numberposts’ => -1,
    ‘meta_key’ => ‘date’,
    ‘orderby’ => ‘meta_value’,
    ‘order’ => ‘DESC’
    ));

    but it’s not working.

  • Unread

    Datepicker fields

    hi!

    How to add multiple datepicker fields. First one is the main datepicker and other fields shows value based on that. For example on first one you select the date 12/2/2023. Second field show instantly week number automatically and the third one shows date + 7 days from the original date.

    I have a lunch list where is lunch menu for each day of the week showing lunch and the date. It would be helpful that you only have to pick a one date and others are calculated automatically.

  • Solved

    Datepicker to text field

    I want to have a text field but with a date picker. Or a date field with the possibility to write free text if I don’t want a date right now. It’s for a job board and sometimes we have a starting date for the position but sometime we just want to write “As soon as possible” or “Later this year”.

    Any idéas? 🙂

  • Helping

    Date Picker years before 1000

    Hi,
    we have an issue with the date picker field. If you want to enter dates before the year 1000 this is not possible. Neither 01/01/0818 nor 01/01/818 are working. Instead it jumps to 1918.

    The solution in this thread does not work for this issue, as mentioned in a comment there:
    https://support.advancedcustomfields.com/forums/topic/date-picker-field-starting-from-before-1913/

    What can we do? We have a website with historical data and need to be able to enter dates up until the year 200.

    Thanks for any input.
    Cheers Sascha

  • Helping

    WordPress Loop and Date Picker Problem

    Hello to all,

    I have created a custom post type in which I enter holidays and days that repeat every year.

    To enter the date I have taken the ACF Datepicker.

    This saves the date format in the database but always in the format: “YYYYMMDD”.

    The entered days are displayed in two loops in the template. One which shows the future days from today. And once the days, which are past and come only in the next year again.

    $args_future = array(
                'post_type' => 'repeat-days',
                'meta_key' => 'repeat_day_date',
                'posts_per_page' => -1,
                'orderby' => 'meta_value',
                'order' => 'ASC',
                'meta_query' => array(
                    array(
                        'key' => 'repeat_day_date', // ACF Feld Name
                        'compare' => '>=',
                        'value' => date("Y-m-d"),
                        'type' => 'DATE'
                    )
                ),
            );

    For the output, however, the year is uninteresting for me.

    Can I somehow tell the wordpress loop that it should only take into account the months and days?

  • Solved

    Save ACF custom field to date-time post

    Is it possible to set the “publish date” of my custom posts with a ACF datepicker field?

    My acf date picker field (startdate) is within a acf repeater field (courseinfo).

    Tried the following code, but didn’t work out (after publishing, the post date was set to january 1970).

    // Save ACF custom field to date-time post
    function my_acf_save_post( $post_id ) {
        $acfDate = get_post_meta($post_id, 'courseinfo_0_startdate', true);
        $my_post = array();
        $my_post['ID'] = $post_id;
        $my_post['post_date'] = $acfDate;
        wp_update_post( $my_post );
    }
    add_action('acf/save_post', 'my_acf_save_post', 20);

    Someone can help me out?

  • Unread

    Setting DateTimePicker Values in JS/Jquery????

    I want to set the value of a DateTimePicker field in the admin page by JS/Jquery but actually with no results.

    I googled a lot and tried a lot of suggestions with now more result.

    I get the data from a AJAX/JSON script and want to prefill the field.

    Any suggestions for me?

  • Solving

    datepicker return today's day if field empty

    hi. i’ve seen this reported if strtotime is used, which i do. i have a ‘single_event_date_end’ datepicker field which returns today’s (current) date if i leave the field empty, and i’d prefer it to return nothing, but i’m struggling to write a function that achieves this.

    the code i’ve tried is (variations on):

    function event_date_end()
    {
        $event_date_end = get_field("single_event_date_end"); 
    
        if ($event_date_end == null) {
            return false; 
        } else {
            return $event_date_end;     }
    }

    any advice appreciated. hiding it isn’t the problem; i’d just like null to = null.
    thanks in advance!

  • Solving

    Change the order in relationship picker

    Why doesn’t this work to change the order in a relationship picker (seen while editing post)

    add_filter('acf/fields/relationship/query/key={field_62585c13349c2}', 'my_acf_fields_relationship_query', 10, 3);
    function my_acf_fields_relationship_query( $args, $field, $post_id ) {
    
        // change the order in the relaionship picker
        $args['orderby'] = 'date';
    
        return $args;
    }
  • Solving

    Date Picker: Query Born Today (over regular posts)

    I been going around for three days, and I just can´t figure this out. I need to display a list of posts based on the day/month, that equals to present day/month, set up with date picker. I have the following code that works perfectly for posts based on their published date, day/month, altough not custom fields, and would be great to adapt it somehow to Date Picker:

    <?php
    $posts_from_today = new WP_Query( array(
        'date_query' => array(
            array(
                'month' => date( 'n', current_time( 'timestamp' ) ),
                'day' => date( 'j', current_time( 'timestamp' ) )
            ),
        ),
        'posts_per_page' => -1,
    ) );
    
    if( $posts_from_today->have_posts() ){
        while( $posts_from_today->have_posts() ){
            $posts_from_today->the_post();
            the_title();
        }
    }
    ?>
  • Solved

    If statement for a false selection

    I’m trying to hide a div if a true/false is un-checked or a date has passed from the date picker. I’ve got the date picker part working, but I can’t get the true/false bit to work.

    From my limited php knowledge and reading the docs, I have this;

    $false = get_field('deposit_required', false, false);

    which is then used in this line of code;
    <div <?php if($date_passed == "date-passed" || $false == 'true') echo 'class="display-none"'; ?> class="container " id="deposit_box">

    I’m thinking its something really simple I’ve overlooked as looking at other threads, it seems a simple thing to achieve.

    Thanks
    Wayne

  • Unread

    Display ACF Taxonomy fields by id custom-post-type in a React App with Rest API

    Hello,
    i hope if some of you could help me

    i Have a custom post type (project)
    each ‘project’ has a custom taxomony (area_project)
    this taxonomy has a ACF field ‘color-picker'(colore)

    how can i display this field (colore) in a react map?

    in function.php i’m trying something with register_rest_field, but i can’t connect the taxonomy with the post id
    the following code return my only the ACF fields of the post , not the field in taxonomy connected to the post

    
    function register_rest_project_fields(){
        register_rest_field(
      		[ 'post', 'page', 'project', 'area_project' ], // add post types here
      		'acf_fields', // name of the field
      		array(
      			'get_callback'    => 'get_acf_fields_for_api',
      			'update_callback' => null,
      			'schema'          => null,
      		)
      	);
    }
    function get_acf_fields_for_api( $object, $field_name, $request ) {
    	$data = get_fields( get_the_ID() );
    	return $data ?: false;
    }
    add_action('rest_api_init', 'register_rest_project_fields' );
    

    Some of you have some solution?
    Thanks in advance

  • Solved

    Auto Update Field based on ACF Date Picker field

    Hey everyone,

    i really need some help with my code.

    I have a custom post type named “coupon”. With ACF i added two fields. The first is a Date Picker field named “coupon_valid_till” with my expiration Date. The second one is a true/false field named “is_expired”. I want to change the value of the true/false field to false if the expiration date is reached.

    First i saw this thread:

    https://support.advancedcustomfields.com/forums/topic/auto-update-fields-based-on-expired-date/

    But that didn´t work.

    I then found this pretty similar thread:

    https://support.advancedcustomfields.com/forums/topic/publish-expire-posts-based-on-acf-date-picker-field/

    From the Answers in the Thread, this code should work. But i don´t need to change the Post from public to draft. So i changed this:

      if (($expiredate < $today) && ($expiredate != "")) { // if date is less than today, but also not empty to accomodate the coupons that don't expire
                    $postdata = array(
                        'ID' => $p->ID,
                        'post_status' => 'draft'
                    );
                    wp_update_post($postdata);
                 }      

    to that:

      if (($expiredate < $today) && ($expiredate != "")) { // if date is less than today, but also not empty to accomodate the coupons that don't expire
                  update_field('is_expired', 0, $post->ID);
                 }      

    But it dint´t work either. I managed to setup a cronjob for the code, which gets executed – but nothing happens.

    It would be great if someone could help me.

    Kathi

Viewing 25 results - 26 through 50 (of 784 total)