Php 自定义字段(ACF)图像不是单一post it&x27;s上载到并显示在我创建的每个帖子类型上
我已经为患者库创建了带有自定义字段(ACF)的自定义帖子类型。为了上传图片,我创建了一个自定义字段类型“Gallery”。问题是,当我在一篇文章上上传一个图像时,这些图像最终会显示在文章类型的每个实例上。我可以创建20种不同的帖子类型,它们都有相同的图片,它们不是我上传到的帖子类型独有的Php 自定义字段(ACF)图像不是单一post it&x27;s上载到并显示在我创建的每个帖子类型上,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我已经为患者库创建了带有自定义字段(ACF)的自定义帖子类型。为了上传图片,我创建了一个自定义字段类型“Gallery”。问题是,当我在一篇文章上上传一个图像时,这些图像最终会显示在文章类型的每个实例上。我可以创建20种不同的帖子类型,它们都有相同的图片,它们不是我上传到的帖子类型独有的 <div class="swiper-container gallery-top gallery-top-home"> <div class="swiper-wrapper">
<div class="swiper-container gallery-top gallery-top-home">
<div class="swiper-wrapper">
<?php while ( $ba_loop->have_posts() ) : $ba_loop->the_post(); ?>
<?php
$images = get_sub_field('ba_photo');
?>
<?php foreach( $images as $image ): ?>
<div class="swiper-slide">
<img class="img-fluid" src="<?php echo $image['url']; ?>">
</div>
<?php endforeach; ?>
<?php endwhile; ?>
</div><!-- swiper wrapper end-->
</div><!-- swiper container end-->
">
我认为首先你需要获得特定帖子的id
使用此代码。。
$images=get_post_meta($post->ID,'ba_photo',true)
而不是这个
$images=get_sub_字段('ba_photo')
第一个代码将根据id区分每个帖子,您将获得所需的帖子详细信息。我认为您首先需要获得特定帖子的id 使用此代码。。 $images=get_post_meta($post->ID,'ba_photo',true) 而不是这个 $images=get_sub_字段('ba_photo')
第一个代码将根据id区分每个帖子,您将获得所需的帖子详细信息。为每个帖子类型使用不同的模板,或者添加条件-
if($post->post\u type=='my post type'),然后显示图库。
。为每个帖子类型使用不同的模板,或者添加条件-if($post->post\u type=='my post type'))然后显示多媒体资料
。