Modify the Query to multiple dates in a post For Advanced Custom Field "Repeater Field"
For each Date and Time
set in the Repeater Field
, only the scheduled events are output to Archive Page.
- The
Date and Time
set in theLoop Field
is outputted asone event
. - Displayed in order of the most recent event (
ASC
). - Closed events is not outputted.
- Supply a
function
for calendar 📅
- PHP 5.3+
- Activation Advanced Custom Field Plugin.
- Create a
Repeater Field
, andDate Field
in the Repeater Field w/ Advanced Custom Field Plugin. - A 6-pack of beer🍺 (optional, I guess.)
cd /path-to-your/wp-content/plugins/
git clone [email protected]:sectsect/acf-repeater-field-query.git
- Activate the plugin through the 'Plugins' menu in WordPress.
You can access the some setting by going toSettings
->ACF Repeater Field Query
. - Setting
Post Type Name
,Repeater Field Name
,Date Field Name
in Loop Feld".
( Optional Field:Taxonomy Name
,StartTime Field
,FinishTime Field
)
That's it:ok_hand:
The main query of your select post types will be modified.
- Tested on ACF
v5.5.5
- If you want to apply to some existing posts, Resave the post.
- Supports Page
is_date()
includesis_year()
is_month()
is_day()
. - If you have set the 'FinishTime', it does not appear that post when it passes your set time. (Default: The Day Full)
You can get a sub query using the new ACF_RFQ_Query()
<?php
$ary = array();
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$perpage = 10;
$offset = ($page - 1) * $perpage;
$args = array(
'posts_per_page' => $perpage
);
$query = new ACF_RFQ_Query($args);
?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
// something
<?php endwhile; ?>
<?php endif;?>
<?php wp_reset_postdata(); ?>
<?php
$dates = array();
$args = array(
'posts_per_page' => -1,
'calendar' => true, // For get the data from not today but first day in this month.
);
$query = new ACF_RFQ_Query($args);
?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php
$date = date('Ymd', strtotime($post->date));
array_push($dates, $date);
?>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
<?php
// Passing array to acf_rfq Calendar Class.
$dates = array_unique($dates); // Remove some Duplicate Values(Day)
$months = get_months_from_now(3);
$args = array(
'dates' => $dates, // (array) (required) Array of event Date ('Ymd' format)
'months' => $months, // (array) (required) Array of month to generate calendar ('Ym' format)
'weekdayLabel' => 'default', // (string) (optional) Available value: 'default' or 'en' Note: 'default' is based on your wordpress locale setting.
'weekdayBase' => 0, // (integer) (optional) The start weekday. 0:sunday ~ 6:saturday Default: 0
'element' => 'div', // (string) (optional) The element for wraping. Default: 'div'
'class' => '' // (string) (optional) The 'class' attribute value for wrap element. Default: ''
);
acf_rfq_calendar($args);
?>
<?php
$ary = array();
$args = array(
'posts_per_page' => -1,
'calendar' => true // For get the data from not today but first day in this month.
);
$query = new ACF_RFQ_Query($args);
?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
$date = date('Ymd', strtotime($post->date));
$post_id = $post->ID;
$perm = get_the_permalink();
$title = get_the_title();
array_push($ary, array('date' => $date, 'id' => $post_id, 'permlink' => $perm, 'title' => $title));
?>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
<?php
// Passing array to your Calendar Class.
require_once 'Calendar/Month/Weeks.php';
calendar($ary, 0);
?>
<div id="date">
<?php echo date('Y-m-d', strtotime($post->date)); ?>
</div>
<time>
<?php echo date("H:i", strtotime($post->starttime)); ?> ~ <?php echo date("H:i", strtotime($post->finishtime)); ?>
</time>
- num
(integer) (required) Number of months to get.
Default:1
(array)
Ym
formatted.
$months = get_months_from_now(3);
-
dates (array) (required) Array of event Date ('Ymd' format).
-
months (array) (required) Array of month to generate calendar ('Ym' format)
-
weekdayLabel (string) (optional) Available value:
'default'
or'en'
.
Default:'default'
📝'default'
is based on your wordpress locale setting. -
weekdayBase (integer) (optional) The start weekday. 0:sunday ~ 6:saturday
Default:0
-
element (string) (optional) The element for wraping.
Default:'div'
-
class (string) (optional) The 'class' attribute value for wrap element.
Default:''
<?php
$args = array(
'dates' => $dates,
'months' => $months,
'weekdayLabel' => 'default',
'weekdayBase' => 0,
'element' => 'div',
'class' => 'myclass'
);
acf_rfq_calendar($args);
?>
- This Plugin does not hosting on the wordpress.org repo in order to prevent a flood of support requests from wide audience.
See CHANGELOG file.
- Create an issue and describe your idea
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Publish the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Profit! ✅
See LICENSE file.
I also have plugin with the same functionality for Custom Field Suite Plugin.