sectsect / acf-repeater-field-query
修改帖子中的查询以支持多个日期的 'Repeater Field' 高级自定义字段。
v1.1.5
2017-11-15 15:15 UTC
Requires
- php: >=5.3
This package is auto-updated.
Last update: 2024-09-26 05:44:12 UTC
README
修改帖子中的查询以支持多个日期的 Advanced Custom Field "Repeater Field"。
特性
对于在 "Repeater Field" 中设置的每个 日期和时间,只有计划中的事件会输出到存档页面。
- 在 "Loop Field" 中设置的
日期和时间作为一个事件输出。 - 按最近的事件顺序(
ASC)显示。 - 不输出已关闭的事件。
- 为日历提供
函数📅
要求
- PHP 5.3+
- 激活 Advanced Custom Field 插件。
- 在 "Advanced Custom Field" 插件中创建 "Repeater Field",并在 Repeater Field 中创建 "Date Field"。
- 一箱啤酒🍺(可选,我想。)
安装
cd /path-to-your/wp-content/plugins/git clone git@github.com:sectsect/acf-repeater-field-query.git- 通过 WordPress 中的 "插件" 菜单激活插件。
您可以通过访问设置->ACF Repeater Field Query来访问一些设置。 - 在 "Loop Feld" 中设置
Post Type Name、Repeater Field Name、Date Field Name。
(可选字段:Taxonomy Name、StartTime Field、FinishTime Field)
就这样:ok_hand
您选择的文章类型的主查询将被修改。
字段结构示例
备注
- 在 ACF
v5.5.5上测试过 - 如果您想将其应用于某些现有帖子,请重新保存帖子。
- 支持页面
is_date()包括is_year()is_month()is_day()。 - 如果您已设置 "FinishTime",则在该时间过后不会显示该帖子。(默认:整天)
用法示例
您可以使用 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(); ?>
示例:用于日历的子查询(使用 acf_rfq_calendar())
<?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); ?>
示例:获取 "Date","StartTime" 和 "FinishTime"
<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>
函数
get_months_from_now($num)
参数
- num (整数) (必需)要获取的月份数。
默认:1
返回值
(数组)
Ym 格式。
$months = get_months_from_now(3);
acf_rfq_calendar($args)
参数
-
dates (数组) (必需)事件日期数组('Ymd' 格式)。
-
months (数组) (必需)要生成日历的月份数组('Ym' 格式)。
-
weekdayLabel (字符串) (可选)可用值:
'default'或'en'。
默认:'default'
📝'default'基于您的 WordPress 区域设置。 -
weekdayBase (整数) (可选)开始周几。0:周日 ~ 6:周六
默认:0 -
element (字符串) (可选)包装元素。
默认:'div' -
class (字符串) (可选)包装元素的 'class' 属性值。
默认:''
示例
<?php $args = array( 'dates' => $dates, 'months' => $months, 'weekdayLabel' => 'default', 'weekdayBase' => 0, 'element' => 'div', 'class' => 'myclass' ); acf_rfq_calendar($args); ?>
开发人员备注
- 此插件不在 wordpress.org 仓库中托管,以防止大量来自广大受众的支持请求。
变更日志
请参阅变更日志文件。
贡献
- 创建一个问题并描述您的想法
- 进行Fork
- 创建您的功能分支(
git checkout -b my-new-feature) - 提交您的更改(
git commit -am '添加一些功能') - 发布分支(
git push origin my-new-feature) - 创建新的拉取请求
- 获利!✅
许可证
请参阅许可证文件。
相关插件
我还有一个与自定义字段套件插件相同功能的插件。