【问题标题】:ACF repeater field with multiple subfields checked by today date具有多个子字段的 ACF 转发器字段在今天日期之前检查
【发布时间】:2019-01-26 07:17:13
【问题描述】:

我有一个名为“今天”的自定义字段(中继器)。在其中,我有一个“选择日历日期”子字段。

在产品 (woocommerce) 上,我添加了 1、2、3 个或更多日期。返回日期类似于 dd/mm,我将今天的日期与类似的日期(d/m)进行比较。

问题是加载时间非常长,我没有得到任何结果......

我尝试过的:

$today = date('d/m');

$args = array(
    'numberposts'   => -1,
    'post_type'     => 'product',
    'meta_query'    => array(
        'relation'      => 'AND',
        array(
            'key'       => 'today_$_mdate',
            'compare'   => '=',
            'value'     => $today
        )
    )
);

    $the_query = new WP_Query( $args );

    if( $the_query->have_posts() ): ?>
    <ul>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endwhile; ?>
    </ul>
<?php else:
    echo "No prods"; endif; ?>

<?php wp_reset_query(); 

转发器字段:today

子字段:date

为什么我不能只返回转发器字段子字段设置为的产品 今天的日期? 它甚至不退货。

这是 WP 中的产品句柄:http://prntscr.com/kkobbb

这是自定义字段集:http://prntscr.com/kkobqo

$today returns `20/08`

新方法:

$today = date('d/m');

$args = array(
    'post_type'      => 'product',
    'posts_per_page' => -1
);

$products = new WP_Query( $args );

if ( $products->have_posts() ) {
  echo '<ul>';
    while ( $products->have_posts() ) {
        $products->the_post();
        if( have_rows('today') ):
            while ( have_rows('today') ) : the_row();
                the_sub_field('mdate');
            endwhile;
        else :
            // no rows found
        endif;
    }
  echo "</ul>";
}

wp_reset_query();

还有大量的加载时间...和消息Fatal error: Allowed memory size of 536870912 bytes exhausted... in wp-includes/plugin.php on line 179

但至少,我可以根据其转发器子字段过滤产品。

【问题讨论】:

  • 您的日期字段的“保存格式”是什么?
  • @OutsourceWordPress 很抱歉延迟回答。我的保存/返回格式设置为自定义 d/m,如下图所示:prntscr.com/kkpcyc
  • 您能确保您使用的是最新版本的 ACF 和 ACF 中继器插件吗?
  • 它是专业版并且完全更新。我的插件不需要更新。
  • 那么可能是你的内存限制非常低,尝试将其添加到'wp-config.php' - define( 'WP_MEMORY_LIMIT', '256M' ); 并再次检查。

标签: wordpress advanced-custom-fields acfpro


【解决方案1】:

此问题已修复。从 ACF 自定义字段设置中,只需将转发器字段架构设置为行而不是表。对我来说,它被设置为表格,我有很大的加载时间和崩溃。

【讨论】:

    猜你喜欢
    • 2020-09-20
    • 2018-04-12
    • 2013-04-09
    • 2018-10-06
    • 1970-01-01
    • 2019-05-24
    • 2016-06-17
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多