【问题标题】:ACF wp_query, get the final field of the chain, which is located in => repeater-> field-> repeater-> FIELDACF wp_query,获取链的最终字段,位于=>repeater->field->repeater->FIELD
【发布时间】:2020-12-29 17:08:51
【问题描述】:

最后一个字段是密码,正如我在图片中标记的那样
这是我如何尝试获取该字段的代码..

add_filter('posts_where', 'yanco_posts_where');
function yanco_posts_where( $where ) {
    $where = str_replace( "meta_key = 'repeater_machines_password_repeater_$", "meta_key LIKE 'repeater_machines_%_password_repeater_%", $where );
    return $where;
}

    if(isset($_GET['password'])) {
        $password = sanitize_text_field( $_GET['password'] );
        $meta_query[] = array(
            // 'key' => 'repeater_machines_$_password', // Format: repeater_field + _ + $ + _ + repeater_sub_field password_repeater
            'key' => 'repeater_machines_$_country_password_repeater_$_password',
            'value' => $password,
            'compare' => '='
        );
    }

【问题讨论】:

  • 你到底想做什么?您是否尝试根据 ACF Codex 获取字段,例如 support.advancedcustomfields.com/forums/topic/…
  • 我只想让我的搜索字段正常工作。为此,我需要捕获中继器中的最后一个字段并将其放入 KEY 中。
  • 问题是,我有转发器 > 字段 + 转发器 > 在这个转发器中我有一个文本字段,我需要捕获并放入 meta_query 中的 KEY 中。我真的很感谢你的回复!非常感谢,希望你能帮助我
  • 正如您在该链接上看到的那样,您可以使用 count() 获取转发器的数量,并使用该值创建 if 状态以获取最后一个转发器中的文本字段值。

标签: php wordpress advanced-custom-fields


【解决方案1】:

您可以使用count() 获取转发器的数量,并使用该值创建if 状态,以获取最后一个转发器中的文本字段值。 此外,就像我在评论中发送给您的示例一样,您可以创建计数器$i,您将在if 条件下使用类似比较。 如果您不使用查询,则可以传递第二个参数,例如 Post ID。

<?php
$count_repeater = count( get_field('nameOfRepeater', $post->ID) );
    if($i == $count_repeater) {
     // Get value from text field in last repeater
     $text_value = get_field('nameOfTextField', $post->ID);
    }

【讨论】:

  • 好的。我明白。但无论如何,我需要使用查询来使我的搜索工作。任何想法如何把它放在'KEY' => ...?
  • 所以你想传入你创建的最后一个中继器,并通过该键值进行搜索?
  • 是的,完全正确。但是最后一个转发器字段,位于我在这篇文章中提到的那个链中..我不明白该怎么做..(
  • 您是否尝试为此做一些其他逻辑?
  • 我认为您错过了 KEY 末尾的数字,该数字将代表最后一个中继器并从字段中传递 slug,请检查此答案循环support.advancedcustomfields.com/forums/topic/…
猜你喜欢
  • 2018-03-27
  • 2019-11-19
  • 2018-07-04
  • 2011-09-14
  • 2022-11-15
  • 1970-01-01
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
相关资源
最近更新 更多