Support

Account

Home Forums Search Search Results for 'date picker'

Search Results for 'date picker'

topic

  • Unread

    Date Picker Return Display?

    Hi,
    Is anyone having issues with Date Picker?
    The Display Format turns out perfectly in Admin page but in my actual html,
    the Return Format turns out as STRING(<p>20250423</p>) no matter what display I choose.
    Any masters of ACF or PHP?
    Thank you.

  • Unread

    Modify Date Picker field to allow typed-in values?

    The company I work with has many clients who enter dates alllll day. Sometimes it would be just quicker for them to enter “01/23/1945” than it would be to click on the year field and scroll to 1945, then click on the month field and scroll to January and then finally click on the 23rd. Is there a simple way to modify the code to allow a user to just type in the date?

    Thanks!

  • Solved

    How can I manually change a datetime picker value

    I have a hidden datetime field in a repeater. When a repeater row is duplicated, I would like to change the datetime value. I have tried using acf.getField and then setting
    field.val( new-date-string)
    also
    jQueryElement.attr('value', new-date-string)
    and
    jQueryElement.val(new-date-string)
    finally
    jQueryElement.datepicker('setDate', new-date-string)
    none of these seem to alter the datetime value. I’m assuming maybe I’m accessing the wrong element but I’m not sure which one I should get?

  • Unread

    ACF Date Sort

    Hello!

    Kind of a complicated question here. I have a custom post type that has posts created programatically when a new item is created in SoundCloud. These posts have ACF fields – among them is an event_date field that is a datepicker. All is working perfectly with the post creation. The issue is that I display those posts on the front end of my website and they are sorted in DESC order on the event_date field. However the posts appear out of order when they are first created. If I open up the post in the WP Admin and then save them (without changing anything) then they will be correctly sorted. Its like that field has to be re-initialized after the post is created programatically with a manual save. Any ideas how to resolve the issue without going into each post? I did build a cron that ran wp_udpate_post on each post with just the post ID as an argument, but it didn’t resolve the issue.

    Thanks!

  • Unread

    How to get DatePicker field value in date_picker_args

    I have two DatePicker fields and I have code to set minDate for the second one so that it cannot be earlier than the first. The code is at: https://www.damiencarbery.com/2020/06/acf-date-picker-set-end-date-to-after-start-date/

    I am rewriting the JS so that it sets minDate on page load instead of waiting for the first DatePicker to be changed.

    I am using the ACF JS API:
    acf.addFilter('date_picker_args',.....
    and
    datepicker_value = args['altField'][0]['value'];

    Is args['altField'][0]['value'] the right way to get the field value?
    It seems a little hacky. I don’t see an API function in https://www.advancedcustomfields.com/resources/javascript-api/ to get the value.

  • Helping

    Incorrect return format from date and time

    Hi
    I’m using two custom fields from ACF, one date picker and one time picker. I’m also using a block theme and Full Site Editing. When displaying the date and time on the front-end I get the incorrect format. Date is YYYYMMDD and time for example 19:00:00 instead of the settings I use in ACF.

    To get ACF to work with Full Site Editing I used the following PHP snippet for date and a similar for time:

    register_meta(
    'post',
    'start_date',
    array(
    'object_subtype' => 'event',
    'show_in_rest' => true,
    'single' => true,
    'type' => 'string',
    'sanitize_callback' => 'wp_strip_all_tags'
    )
    );

    I also got some help with trying to correct the date format using this PHP snippet instead:

    register_meta(
    'post',
    'start_date',
    array(
    'object_subtype' => 'event',
    'show_in_rest' => array(
    'schema' => array(
    'format_callback' => function($meta_value, $meta_key, $object_type, $object_subtype, $field_args) {
    return date('F j, Y', strtotime($meta_value));
    },
    ),
    ),
    'single' => true,
    'type' => 'string',
    'sanitize_callback' => 'wp_strip_all_tags'
    )
    );

    On the template itself for displaying the date and time fields on the front-end I used the new block binding, biding it to a paragraph block like so:

    <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"start_date"}}}}} -->
    <p></p>
    <!-- /wp:paragraph -->

    I should probably mention that I don’t know PHP. For the snippets I used guides on how to achieve custom fields with the new block binding feature.

    Is there a way to get the correct date and time format on the front-end? Thank you in advance!

  • Unread

    Datepicker Error When ACF and Advanced Schedule Posts Used Together

    I am using Advanced Custom Fields (Version 6.3.3) on my WordPress (version 6.5.5) website. I am also using Advanced Schedule Posts (Version 2.1.8 from https://github.com/hijiriworld/advanced-schedule-posts) on this website. These two plugins have worked together in the past but with the latest versions of WordPress and the plugins they no longer work for datepicker.

    With Advanced Custom Fields ACTIVATED and Advanced Schedule Posts ACTIVATED
    – Advanced Custom Fields datepicker fails to work
    – Advanced Schedule Posts datepicker fails to work

    With Advanced Custom Fields ACTIVATED and Advanced Schedule Posts DEACTIVATED
    – ACF datepicker works correctly

    With Advanced Custom Fields DEACTIVATED and Advanced Schedule Posts ACTIVATED
    – Advanced Schedule Posts datepicker works correctly

    The console error I get when trying to use the ACF datepicker or Advanced Schedule Posts datepicker in the WordPress admin is below,

    Uncaught TypeError: $(…).zIndex is not a function
    at HTMLInputElement._showDatepicker (jquery.datePicker.min.js?ver=e95bb7bd8a621b465f58e64aa952b821:746:31)
    at HTMLInputElement.dispatch (load-scripts.php?c=1&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils,wp-polyfill-inert,regenerator-runtime,wp-polyfill,wp-hooks&ver=e95bb7bd8a621b465f58e64aa952b821:2:40035)
    at v.handle (load-scripts.php?c=1&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils,wp-polyfill-inert,regenerator-runtime,wp-polyfill,wp-hooks&ver=e95bb7bd8a621b465f58e64aa952b821:2:38006)

  • Solved

    Filtering posts between two dates, based on selected month, with a meta query

    I have some filters on my post archive and one of them is a month dropdown. The post type has 2 custom fields, one for start date and one for end date. I am trying to add a meta query to retrieve posts where the selected month falls between these two dates.

    IE if a post has a start_date of 20240502 and the end_date is 20240815, for example, it would always show up if the user selected any month between May(05) and August(08).

    I tried modifying a response from another post I found:

    $sel_month = '05';
    $meta_query[] = array(
        'relation' => 'OR',
        array(
            'key'      => 'start_date',
            'compare'  => 'REGEXP',
            'value'    => '[0-9]{4}' . $sel_month . '[0-9]{2}',
        ),
        array(
            'key'      => 'end_date',
            'compare'  => 'REGEXP',
            'value'    => '[0-9]{4}' . $sel_month . '[0-9]{2}',
        )
    );

    But with this, it will only show the post if the start_date month is selected or the end_date month is selected but not any of the months between.

    Any ideas how I can modify this query to show all posts where the selected month falls between the start_date and end_date of the post?

  • Unread

    pre_get_posts query to sort after date_picker

    Hi, i would like to sort all posts according to the date of my start_time meta field. But no matter what i try i always get Nothing Found. Also had no luck when i try get_posts or a WP_Query.

    What am i doing wrong?

    Here’s the code:

    function mind_pre_get_posts( $query ) {
      
      if( is_admin() ) {
        return $query; 
      }
      if( $query->is_main_query() ) {
        
        $query->set('orderby', 'meta_value'); 
        $query->set('meta_key', 'start_time');   
        $query->set('order', 'DESC'); 
        
      }
      return $query;
    }
    add_action('pre_get_posts', 'mind_pre_get_posts');

    And here’s the custom field group:

    
    	acf_add_local_field_group(array(
    		'key' => 'group_1',
    		'title' => 'Meta info',
    		'fields' => array (
               		 array (
    				'key' => 'start_time',
    				'label' => 'Exhibition start',
    				'name' => 'exhibition_start',
    				'type' => 'date_picker',
    			),
              		  array (
    				'key' => 'end_time',
    				'label' => 'Exhibition end',
    				'name' => 'exhibition_end',
    				'type' => 'date_picker',
    			)
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'post',
    				),
    			),
    		),
    	));
    
    
  • Solving

    How do I list events without a set date?

    I have an event page set up using ACF which lists out all events I have created sorted by date, and if the date has passed, they are shown in a separate list for past events.
    Now, my issue is that I want to create events with no set date (i.e. date picker left blank), but how do I include these in the same list when the loop is sorted on dates?

  • Unread

    My “Time Picker” field has become a Date field

    Hello,

    I have used the same Time Picker field for many years, but as of today (March 12 24), when using the field in a post it has become a date only field. For example, instead of being able to enter 06:00 am, I can only select a date from a pop-out calendar, which always becomes 12:00 am upon saving. The field is still set to Time Picker in the settings.

  • Solving

    Date picker hide year for current year, and show it for future years

    Hello ! I have a band site, made with elementor PRO and ACF. I use CPT for my events. I’ve already been able to order them in various loops and archives by ACF custom field date and to hide previous ones, with some php snippets.

    Now, I would like to display the year only for future years.
    ex: 2024/03/12 would display “12 march” and 2025/03/12 would display “12 march 2025”

    I am not good enough in php to get it working with found resources on my own. Can you help me ? Thanks !!!

    https://newmoon-pinkfloydexperience.fr/agenda-des-concerts/

  • Unread

    Date picker as expiry for custom field

    Hi,

    I’m hoping someone can help me out with the issue that I have encountered with the ACF date-picker field.

    I have created an announcement banner for a website through ACF. The announcement banner consists of 2 fields. One field with the banner message (textarea field) and another field as an expiry date (datepicker field) for the banner.

    Snippet of the code I am using is below.

    <?php
    $current_date_time = current_datetime()->format(‘d/m/Y’);
    $noticeExpiry = get_field(‘notice_expiry’, ‘options’)
    ?>

    <?php if ($noticeExpiry > $current_date_time ) {?>
    <div class=”notice-banner”>
    <div class=”wrap”>
    <?php the_field(‘website_notice’,’options’) ?>
    </div>
    </div>
    <?php } ?>

    As you can see I have a conditional statement that checks todays date against the notice expiry and if the $noticeExpiry is a future date compared to the current date the notice banner will display.

    The problem that I am having is that the condition only appears to with working with the numeric value of the days.

    If I set the expiry as yesterday (11/2/24) then all is working as expected. The banner will not appear. However if I change the date to a date that exceeds the 11th date of a previous month the banner appears. Something I spotted when I was testing. I changed the expiry date to 29/1/24 and when I published the change the banner started to appear again. If I change the date to 10/1/24 the banner does not appear.

    Appreciate any help on this and apologies if I am missing something super basic.

  • Unread

    Need help with date function

    Hi there,

    I want to autogenerate title and slug from ACF fields and terms and I’ve already created a function which works nearly perfect. My only issue is, the date output is not working correctly. I don’t want the present date but the correct date from the two custom_fields from date picker. Here is the custom code:

    
    // Create Auto Title for 'Veranstaltungen'
    add_action('save_post', 'wpb_autogenerate_events_title', 10, 3);
    
    function wpb_autogenerate_events_title($post_id, $post, $update) {
        // Check if it's the 'events' CPT and if the title is empty.
        if ('veranstaltungen' !== $post->post_type || !empty($post->post_title)) {
            return;
        }
    
        // Fetch terms from 'category' and 'nameselection' taxonomies.
        $category_term = wp_get_post_terms($post_id, 'veranstaltungskategorie', ['fields' => 'names']);
        $nameselection_term = wp_get_post_terms($post_id, 'winzertax', ['fields' => 'names']);
    
        // Fetch the 'date' custom field created with ACF Pro.
        $date_start = get_field('datum_beginn', $post_id);
    	$date_end = get_field('datum_ende', $post_id);
    	
    	$date_start_form = date( "dmY", strtotime($date_start));
    	$date_end_form = date( "dmY", strtotime($date_end));
    
        // Combine the terms and the date to form the title.
        $new_title = join(' <br>bei ', array_merge((array) $category_term, (array) $nameselection_term));
    	$new_titleslug = join('-', array_merge((array) $category_term, (array) $nameselection_term, (array) $date_start_form, (array) $date_end_form));
    	
        // Prepare the slug from the title.
        $new_slug = sanitize_title($new_titleslug);
    
        // Update the post.
        wp_update_post([
            'ID' => $post_id,
            'post_title' => $new_title,
            'post_name' => $new_slug, // This is the slug.
        ]);
    }
    

    Could you please help me why the output isn’t correct?

  • Solved

    SQL command to update the age field based on date of birth

    Hi good day,

    Hi I add 2 additional fields for users,

    mag_date_of_birth
    mag_age

    Now i try to update the age of all user based on the date of birth thru sql command and here is my command,

    UPDATE wp_usermeta AS m1
    JOIN wp_usermeta AS m2 ON m1.user_id = m2.user_id
    SET m1.meta_value = DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), m2.meta_value)), '%Y') + 0
    WHERE m1.meta_key = 'mag_age'
      AND m2.meta_key = 'mag_date_of_birth'

    now my problem here is when I execute that command it returns and error said “Incorrect datetime value”

    mag_date_of_birth field is datepicker

    where it saves data on database like this “19911207”

    I think 19911207 and 1991-12-07 is different…

    can anyone correct my sql command please…

    screenshots
    https://imgur.com/a/Gv2uxVx

  • Solving

    Only show my posts if the date picker date is still in the future or today

    I would like to display only events in the future or those taking place on the same day. All posts whose date picker start_event is older than today’s date should not be displayed, but I can’t do it…

          <?php $loop = new WP_Query( array( 'post_type' => 'evenement', 'posts_per_page' => 10 ) ); ?>
          <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
      
              <a href="<?php echo get_permalink() ?>">
                <div class="image">
                  <?php echo the_post_thumbnail(); ?>
                </div>
                <div class="description">
                  <div class="dates">
                      <?php echo get_field('start_event') ?> à <?php echo get_field('hour_start_event') ?>
                  </div>
                  <div class="nom">
                    <?php echo the_title(); ?>
                  </div>
                </div>
              </a>
      
          <?php endwhile; ?>
  • Solving

    Validate a post doesn’t conflict with another post’s date/time field

    Ok bear with me on this one, I’ll try and simplify this as much as I can.
    Lets say I have a Custom Post Type of “Events”
    In those events I have a checkbox field for different kinds of events
    -Birthday
    -Anniversary
    -Housewarming etc

    In each post I have 2 date/time pickers one for start time and one for end time. If a start time is in the future the post status is set to “scheduled”.

    I’d like to do a check so no two types of events can be scheduled during the same time. So no two birthday events can have overlapping start and stop times.

    My first thought was to query any posts that are currently have a status of publish or future, then compare all that have the same type checkbox and then compare date/times but I’m not sure if I’m over complicating things…or not complicating things enough.

  • Solved

    timepicker and timezone

    I need to display event CPTs limited by date (today) and time (event is now running).
    To do so, I’m using a meta query comparing

    • a date picker field to date(‘Y-m-d’)
    • a start time picker field to date(‘H:i:s’)
    • an end time picker field to date(‘H:i:s’)

    To be able to use local server time correctly, I need to add date_default_timezone_set(“Europe/Berlin”) before doing php date / time camparisons.

    However, as soon as this is added, all ACF time / date fields start displaying and calculating as UTC time, i.e. a meta entry of 12:15:00 in the database is displayed as 11:15:00 using ACF template functions.

    Even doing ridiculous stuff like
    date_default_timezone_set("Europe/Berlin");
    $starttime = date('H:i:s', strtotime( get_field( 'event_starttime' ) ) );
    doesn’t seem to help.

    Is there an easy way to solve this without having to dive into (to me) incomprehensible and overcomplicated (again, to me) DateTimeImmutable or datefmt_format stuff?

  • Solving

    How to show posts by field date picker

    Hey! I am creating a page that shows peoples namedays. I have created field group(name days) by date (date picker) and name (text)

    I also use Elementor.

    I also have created few example posts via the new item that was automatically created to my wp sidebar (namedays) and inserted there topic, name and date.

    How I can show on my homepage namedays only by todays date? So that when I have created namedays for every single date of the year, my ”posts” would only show the posts that have todays date?

  • Helping

    Change the style based on the day and time

    HI. I would like to ensure that, after the day and time set on the date picker, the “.form-registration” class is assigned the “display: none;” style. How can I do?
    P.S. I use “Code Snippets” of “Code Snippets Pro” to insert the code.

  • Helping

    Custom post type navigation ordered by ACF date field

    Hi there,

    I have a custom post type called ‘prime-ministers’

    On it’s archive page, it is ordered by an ACF date picker field called serving_period_1_start

    This works as expected

    However on each individual page, when I add Prev?next post navigation buttons, it always orders them by published date. I have tried many variations, and it’s always the same.

    This is my current code:

    	<div class="prime-ministers-post-nav full-width blue-bg">
    	<?php
    	 
    	 /* Infinite next and previous post looping */
    	 if( get_adjacent_post(false, '', true) ) { 
    		 previous_post_link('%link', '&larr; Previous Post');
    	 } else { 
    		 $arg_prev = array(
    			 
    			'post_type' => 'prime-ministers',
    			'meta_key' => 'serving_period_1_start',
    			'order' => 'DESC',
    			'orderby' => 'meta_value_num'
    	
    		  );
    		 $first = new WP_Query($arg_prev); 
    		 $first->the_post();
    		 echo '<a href="' . get_permalink() . '" class="prev-link"> &larr; Previous Post</a>';
    		 wp_reset_query();
    	 }; 
    	 
    	 if( get_adjacent_post(false, '', false) ) { 
    		 next_post_link('%link', 'Next Post &rarr;');
    	 } else { 
    		 $arg_next = array(
    			'post_type' => 'prime-ministers',
    			'meta_key' => 'serving_period_1_start',
    			'order' => 'ASC',
    			'orderby' => 'meta_value_num'
    		 );
    		 $last = new WP_Query($arg_next); 
    		 $last->the_post();
    		 echo '<a href="' . get_permalink() . '" class="next-link">Next Post &rarr;</a>';
    		 wp_reset_query();
    	 }; 
    	 
    	 ?>
    	</div>

    I am going a bit mad here, so any help would be greatly appreciated

  • Solved

    Date picker only goes 100 years back

    Hello,

    I have a date field “Birth date” and I noticed that the date picker only goes back to 1923. Therefore, it’s not possible to pick the birth date for people born before 1923. I know that the date can be entered manually, but for some users this is a problem. Is there a way to omit this restriction?

    Regards

  • Solved

    Repeater field meta_query between 2 dates

    I can’t get this to work at all, I’m trying to build into a rest_{post_type}_query but struggling to get it to work on a regular query not sure what I’m doing wrong all so I’m trying to get any results from this query between 2 dates:

    $args = array(
        'post_type' => 'tours',
        'posts_per_page' => -1,
        'meta_query' => array(
            array(
                'key' => 'linked_tours', // Name of the repeater field
                'value' => array( '20230822', '20230925' ), // Array of start and end dates
                'type' => 'DATE',
                'compare' => 'BETWEEN', // To check if the date falls within the range
                )
            ),
    );

    linked_tours is the name of a repeater field on the tours post type containing 2 sub_fields, a datepicker and a post object. I’m trying to return tours between 2 dates but getting no results.

    I’ve tried a few combinations on the ‘key’ that I found on the forum but none working. Sorry if this has been asked before but I haven’t found a solution and any help would be appreciated.

  • Helping

    Merge options repeater fields and custom post type

    I realise this is a big ask but I can’t work out how to do this.

    I have an options page that generates publications that are just a PDF link.

    It asks for a featured image, excerpt, PDF link, and date

    I also have a custom post type called ‘publications’

    I am trying to merge these two together and then output them sorted by date (the date picker for the repeaters and the published date for posts)

    My Repeater field is setup like so:

    <?php if ( have_rows( 'publications', 'option' ) ) : ?>
    	<?php while ( have_rows( 'publications', 'option' ) ) : the_row(); ?>
    		<?php the_sub_field( 'publication_name' ); ?>
    		<?php $publication_image = get_sub_field( 'publication_image' ); ?>
    		<?php if ( $publication_image ) : ?>
    			<img src="<?php echo esc_url( $publication_image['url'] ); ?>" alt="<?php echo esc_attr( $publication_image['alt'] ); ?>" />
    		<?php endif; ?>
    		<?php the_sub_field( 'publication_description' ); ?>
    		<?php $publication_file = get_sub_field( 'publication_file' ); ?>
    		<?php if ( $publication_file ) : ?>
    			<a href="<?php echo esc_url( $publication_file['url'] ); ?>"><?php echo esc_html( $publication_file['filename'] ); ?></a>
    		<?php endif; ?>
    		<?php the_sub_field( 'file_link_description' ); ?>
    		<?php the_sub_field( 'pdf_date' ); ?>
    	<?php endwhile; ?>
    <?php else : ?>
    	<?php // No rows found ?>
    <?php endif; ?>

    My custom post type is just called ‘publications’

    ACF have said I need to:

    Create a Custom Post Type: First, you’ll want to create a custom post type specifically for the publications (e.g., “Publications”).
    Set up ACF Repeater Field: Set up an ACF repeater field group for the additional content that doesn’t fit the typical blog post format. This repeater field can include fields for an image, text, link, and date field (if you want to order by date).
    Add Content as Custom Posts or Repeater Fields: For the actual blog posts, create them using the standard WordPress post editor, and assign the “Publications” custom post type to them. For the other content that consists of just an image and a link to a PDF, use the ACF repeater field to add that information to a specific page or a custom options page.
    Custom Query to Retrieve and Display Content: Now comes the part where you combine both types of content on your publications page. In your page template (or a custom template), you’ll use a custom query to fetch both the regular blog posts and the ACF repeater field data.

    a. Retrieve Blog Posts: Use a regular loop or WP_Query to get the blog posts assigned to the “Publications” custom post type, and display them in a list or grid format.
    b. Retrieve Repeater Field Data: To fetch the data from the ACF repeater field, you can use the get_field function with the appropriate field name and iterate through the rows to display the image, text, and link.
    c. Merge and Sort: Combine the data from both sources into a single array or object and sort them based on the publishing date (you can use the date field in the repeater field).

    Display the Combined Content: Finally, loop through the sorted and merged array/object to display all the content together on the publications page.
    Remember that the actual implementation may vary depending on your specific use case and the structure of your theme. Always make sure to properly sanitize and validate any user-generated content to ensure security.

    This approach should allow you to have a flexible publications page that can include both traditional blog posts and the ACF repeater field content, presented in a unified manner sorted by date.

    But I don’t know how to do this.

    Any help would be greatly appreciated
    Thanks

  • Solved

    Conditional display on specific fields based on post type

    I have a field group that I’m displaying on multiple post types but there are specific fields I’d like to display only on specific post types. Some are fields inside repeater fields others are “Normal” fields.

    For example something like this

    Radio buttons (Post types A and B)
    Text Field (Post types A and B)
    Date time picker (Post Type B only)
    Repeater field 1 (Post types A and B)
    —Image Field (Post types A and B)
    —Url Field (Post types A and B)
    —Date time picker (Post Type B Only )
    Repeater field 2 (Post types A and B)
    —Image Field (Post types A and B)
    —Url Field (Post types A and B)
    —Date time picker (Post Type B Only)

Viewing 25 results - 1 through 25 (of 784 total)