定制 sectsect/acf-repeater-field-query 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sectsect/acf-repeater-field-query

Composer 安装命令:

composer require sectsect/acf-repeater-field-query

包简介

Modify the Query to multiple dates in a post For Advance Custom Field 'Repeater Field'.

README 文档

README

Modify the Query to multiple dates in a post For Advanced Custom Field "Repeater Field"

Features

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 the Loop Field is outputted as one event.
  • Displayed in order of the most recent event (ASC).
  • Closed events is not outputted.
  • Supply a function for calendar 📅

Requirements

Installation

  1. cd /path-to-your/wp-content/plugins/
  2. git clone git@github.com:sectsect/acf-repeater-field-query.git
  3. Activate the plugin through the 'Plugins' menu in WordPress.
    You can access the some setting by going to Settings -> ACF Repeater Field Query.
  4. 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.

Fields Structure Example

NOTES

  • Tested on ACF v5.5.5
  • If you want to apply to some existing posts, Resave the post.
  • Supports Page is_date() includes is_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)

Usage Example

You can get a sub query using the new ACF_RFQ_Query()

Example: Sub 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(); ?>

Example: Sub Query For Calendar (Using 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);
?>

Example: Sub Query For Calendar (Using Your Calendar Class)

<?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);
?>

Example: Get the "Date", "StartTime" and "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>

function

get_months_from_now($num)

Parameters
  • num (integer) (required) Number of months to get.
    Default: 1
Return Values

(array)
Ym formatted.

$months = get_months_from_now(3);

acf_rfq_calendar($args)

Parameters
  • 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: ''

Example
<?php
$args = array(
	'dates'        => $dates,
	'months'       => $months,
	'weekdayLabel' => 'default',
	'weekdayBase'  => 0,
	'element'      => 'div',
	'class'        => 'myclass'
);
acf_rfq_calendar($args);
?>

NOTES for Developer

  • This Plugin does not hosting on the wordpress.org repo in order to prevent a flood of support requests from wide audience.

Change log

See CHANGELOG file.

Contributing

  1. Create an issue and describe your idea
  2. Fork it
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Publish the branch (git push origin my-new-feature)
  6. Create a new Pull Request
  7. Profit! ✅

License

See LICENSE file.

Related Plugin

I also have plugin with the same functionality for Custom Field Suite Plugin.

CFS Loop Field Query

sectsect/acf-repeater-field-query 适用场景与选型建议

sectsect/acf-repeater-field-query 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「wordpress」 「github」 「acf」 「advance custom field」 「Repeater」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sectsect/acf-repeater-field-query 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sectsect/acf-repeater-field-query 我们能提供哪些服务?
定制开发 / 二次开发

基于 sectsect/acf-repeater-field-query 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2017-02-03