希望显示每个中继器行的单独编号。例如,第一行将显示“1”,第二行将显示“2”。
我从艾略特那里找到了这个,
<?php echo count( get_field('repeater_field') );?>
Run Code Online (Sandbox Code Playgroud)
它计算总共有多少行。但我需要每个旁边的个人号码。
谢谢
我正在尝试写一个else语句有些麻烦.基本上,如果转发器字段在那里并显示内容,那么,如果转发器字段中没有内容,则显示此内容.
这是没有我开始的else语句的原始代码
<div class="tabs-panel" id="panel5">
<?php
if ( have_rows( 'ar_content' ) ):
$i = 0;
$n = count( get_field('ar_content') );
?>
<div class="row">
<?php
while ( have_rows( 'ar_content' ) ):
the_row();
$i++;
?>
<div class="small-12 medium-4 columns">
<?php the_sub_field('ar_block'); ?>
</div>
<? if ($i % 3 == 0 && $i < $n) : ?>
</div>
<div class="row">
<?php
endif;
endwhile;
?>
</div>
<? endif; ?>
</div><!-- end panel 5 -->
Run Code Online (Sandbox Code Playgroud)
这是我想要工作的代码.我认为它只是用else替换最后的endif并移动到其他内容?
<div class="tabs-panel" id="panel5">
<?php
if ( have_rows( 'ar_content' ) …Run Code Online (Sandbox Code Playgroud) 我在 WordPress 中使用自定义字段插件,但是当我在“字段组”中添加新字段时,我无法看到中继器字段。
我想允许管理员从 wp 管理面板上传多个图像(任意数量的图像)。
我怎样才能做到这一点?
首先,我想说这不是一个重复的问题,我尝试了其他答案但没有成功。
我将 ACF 字段添加到 woocommerce 类别,我需要在 woocommerce 类别存档页面上显示该字段。
下面显示了我如何添加 ACF
http://www.awesomescreenshot.com/image/1859170/1fb3dc839dff36c92d4ee52f5167ca78
http://www.awesomescreenshot.com/image/1859175/1d1e43f70ae925ac5501f9e360f4a463
它显示在产品类别管理区域
http://www.awesomescreenshot.com/image/1859197/c5df7d20319c73d94896058daa6f3f2a
但是当我尝试在类别页面上显示时,它没有显示,
<?php
$queriedObject=get_queried_object();
echo get_field('categoryslider','product_cat_'.$queriedObject->term_id);
?>
Run Code Online (Sandbox Code Playgroud)
上面的代码是我从堆栈溢出中获得的,我还尝试了其他一些解决方案,但它不起作用,我正在使用所有插件的最新版本。
谁能帮助我吗?谢谢
我正在开发一个自定义主题,并在该主题中包含了 acf pro,如文档中所述。主题工作正常,主题激活时激活了 acf。这是代码。
// customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');
function my_acf_settings_path( $path ) {
$path = get_stylesheet_directory() . '/inc/advanced-custom-fields-pro/';
return $path;
}
// customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');
function my_acf_settings_dir( $dir ) {
$dir = get_stylesheet_directory_uri() . '/inc/advanced-custom-fields-pro/';
return $dir;
}
// Include ACF
include_once( get_stylesheet_directory() . '/inc/advanced-custom-fields-pro/acf.php' );
Run Code Online (Sandbox Code Playgroud)
我现在面临几个小时的问题是由于我想在 acf 中实例化的组/字段。我有一些想要在全新安装时显示的字段组。以下是我尝试过的方法:
方法 1:
我已将字段作为 json 导出到名为acf-json. ACF 确实识别它并显示为同步字段。但是当我尝试同步它时,它只会创建一个新的空字段。
方法 2: 我也尝试将字段组导出为 php 文件,然后将其包含在我的 functions.php 文件中,但 acf 无法识别此代码。
有很多与我相关的主题,但我仍然没有找到解决方案。我正在尝试通过 ACF 字段(单选按钮)查询帖子,似乎 meta_query 被完全忽略。它返回所有帖子,而不是仅返回符合条件的帖子。我尝试过使用字段键而不是字段名称、其他比较等。似乎没有任何效果。希望您知道可能出了什么问题!这是我的代码:
<?php
$post_args = array(
'post_type' => 'products',
'posts_per_page' => - 1,
'status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => 'product_taste',
'meta_value' => array( 'cold' ),
'compare' => 'IN',
),
array(
'meta_key' => 'product_served',
'meta_value' => array( 'grated' ),
'compare' => 'IN'
)
),
);
$query = new WP_Query( $post_args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) : ?>
<?php
$query->the_post();
?>
<h5>
<?php the_title(); ?>
</h5>
<?php endwhile …Run Code Online (Sandbox Code Playgroud) 我正在使用 Wordpress 的高级自定义字段并尝试在组内循环转发器。我得到的只是“注意:数组到字符串的转换......”
出了什么问题,我该如何解决?
<?php if( have_rows('start_horlurar') ): while ( have_rows('start_horlurar') ) : the_row(); ?>
<?php $horlur = get_sub_field('horlur'); ?>
<?php if( have_rows( $horlur['arsmodeller_lankar']) ): while ( have_rows($horlur['arsmodeller_lankar']) ) : the_row(); ?>
<?php echo get_sub_field('lank'); ?>
<?php endwhile; endif; ?>
<?php endwhile; endif; ?>
Run Code Online (Sandbox Code Playgroud) php wordpress while-loop nested-loops advanced-custom-fields
我为 WooCommerce 类别创建了自定义字段。位置如下所示,它们工作正常。
但是,当我转到我的archive.php文件并尝试 a时the_field('category_banner),它没有检索到任何数据。这是我如何布局的示例。
<?php
$categorybanner = get_field('category_banner');
$categorydescription = get_field('category_description');
?>
<div class="container-fluid" id="ivy-banner" style="background: url('<?php echo $categorybanner ?>') center / cover"></div>
<h4 class="text-black"><?php echo $categorydescription; ?></h4>
Run Code Online (Sandbox Code Playgroud)
这段代码不起作用的原因是什么?我只能假设它与位置有关,而不是代码本身。我怎样才能规避这个问题?
抱歉,如果这是多余的。我搜索了很多东西,但 can\xe2\x80\x99t 似乎弄清楚了。
\n\nI\xe2\x80\x99ve 有一个具有开始和结束日期的组。我\xe2\x80\x99d 喜欢按开始日期订购。组\xe2\x80\x99s 名称为showit_event_dates,开始日期为start_event。
\n\n我\xe2\x80\x99已经尝试过ACF使用的方式:
\n\n$args = array (\n 'post_type' => 'showit_events',\n 'posts_per_page' => $num_posts,\n 'orderby' => 'meta_value',\n 'meta_key' => 'start_event',\n 'order' => 'DESC'\n );\nRun Code Online (Sandbox Code Playgroud)\n\n并且还使用meta_query而不是meta_key:
\n\n$args = array (\n 'post_type' => 'showit_events',\n 'posts_per_page' => $num_posts,\n 'orderby' => 'meta_value',\n 'meta_query' => array(\n array(\n 'key' => 'start_event',\n 'value' => date('F j'),\n 'type' => 'DATE',\n 'compare' => '=',\n )\n ),\n 'order' => 'DESC'\n );\nRun Code Online (Sandbox Code Playgroud)\n\n两者都不渲染任何东西。我\xe2\x80\x99m猜测是因为组中的日期被视为数组???
\n\n任何帮助都会很棒。
\n我有一个自定义帖子类型“产品”,我为“选择类别”字段创建了 4 个复选框选项,用户可以一次选择多个选项。出于某种原因,我没有使用分类法对产品进行分类。
因此,当我执行 meta_query 时,它不会产生任何结果。基本上,我已经为自定义帖子类型“产品”中的每个产品选择了类别,但是 ACF 将它的复选框值存储在数组中,并且 meta_query 无法整体搜索该数组。但是它可以从数组中搜索。我的代码如下:
$args = array(
'post_type' => 'fproduct',
'meta_query' => array(
array(
'key' => 'select_product_categories',
'value' => array('Indoor Games', 'Property Management'),
'compare' => 'IN',
),
),
);
// query
$wp_query = new WP_Query( $args );
echo "<pre>"; print_r($wp_query); echo "</pre>"; die;
Run Code Online (Sandbox Code Playgroud)
那么我如何搜索以便复选框可以工作,我也无法获取模板上的复选框值,因为它用于不同产品的帖子类型。
我正在尝试获取循环中帖子的 ACF 归档值。但由于某种原因,该值没有被显示。
我已经尝试过了
<?php $field = get_field('field_name'); echo $field; ?>
Run Code Online (Sandbox Code Playgroud)
和
<?php the_field('field_name', $post->ID); ?>
Run Code Online (Sandbox Code Playgroud)
这些方法都不起作用。请参阅下面的循环代码:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 4,
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-sm-6">
<h2 class="the-title"><?php the_field('field_name', $post->ID); ?> + <?php the_title() ;?> </h2>
</div>
<?php endwhile; else: ?> Nothing here <?php endif; ?>
<?php wp_reset_query(); ?>
Run Code Online (Sandbox Code Playgroud)
如何在循环中获取 ACF 字段值?
wordpress ×9
php ×7
woocommerce ×2
acfpro ×1
count ×1
if-statement ×1
json ×1
nested-loops ×1
repeater ×1
rows ×1
while-loop ×1