Home › Forums › Front-end Issues › Widget Calendar and Date field
Hi,
I use a date field (date picker) for my post as an event date.
I’d like to get this field in the default widget calendar instead of the post_date.
Could someone help me please ?
Thanks
There isn’t any way to do this in ACF. What you’re going to need to do is to create a new custom widget. You can start by copying the existing calendar widget /wp-includes/widgets/class-wp-widget-calendar.php
WP Widget API doc: https://codex.wordpress.org/Widgets_API
Widget turorial: http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/
Hi John,
Thanks a lot for your answer, i’m just surprised there no third party solution, because i suppose it’s a basic need, using and sorting in widget calendar with ACF date field instead of wp post_date.
Thanks
The problem is really that there are no suitable hooks in the built in WP widgets that will let you do anything to modify them. I’ve run into the same thing when I’ve needed other widgets, like a date or category widget for a custom post type.
Ok thanks i understand, so i’ve used a wp calendar widget clone(https://pippinsplugins.com/custom-post-type-calendar-widget/) and i think
instead of using :
// Get days with posts
$dayswithposts = $wpdb->get_results( "SELECT DISTINCT DAYOFMONTH( post_date )
FROM $wpdb->posts WHERE MONTH( date ) = '$thismonth'
AND YEAR( post_date ) = '$thisyear'
AND post_type IN ( $post_types ) AND post_status = 'publish '"
, ARRAY_N );
i suppose i musts do something like :
$args = array (
'post_type' => 'post', // your custom post type
'meta_key' => 'date_de_la_manifestation', // your custom date field name
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'date_de_la_manifestation',
'compare' => 'REGEXP',
'value' => '[0-9]{4}' . $thismonth . '[0-9]{2}',
),
)
);
and after make a loop on result to get the day of my acf field date_de_la_manifestation and displays it in the calendar.
Or if you know how you can use $wpdb as in the first code example and extend the query to join the meta table. Both will result in the same but $wpdb will be faster.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.