Php WordPress-在wp_查询中获取ACF post_对象
是否可以在自定义Php WordPress-在wp_查询中获取ACF post_对象,php,html,wordpress,advanced-custom-fields,Php,Html,Wordpress,Advanced Custom Fields,是否可以在自定义wp\u查询中使用post\u对象字段?我创建了一个模板来列出所有博客帖子,并通过获取帖子格式来获取不同的内容。在其中一种格式中,我想从我创建的自定义post类型中获取post\u对象。我正在努力从那篇文章中获取ACF字段值,即使我在the_field()中传递了第二个参数(ID),它也会让我总是后退,例如,对于一个日期,它总是显示今天的日期 以下是查询代码: $args = array( 'post_type' => 'post', 'post
wp\u查询
中使用post\u对象
字段?我创建了一个模板来列出所有博客帖子,并通过获取帖子格式来获取不同的内容。在其中一种格式中,我想从我创建的自定义post类型中获取post\u对象
。我正在努力从那篇文章中获取ACF字段值,即使我在the_field()
中传递了第二个参数(ID),它也会让我总是后退,例如,对于一个日期,它总是显示今天的日期
以下是查询代码:
$args = array(
'post_type' => 'post',
'post_status' => 'publish'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post();
?>
<?php get_template_part( 'template-parts/content', get_post_format() ); ?>
<?php
endwhile;
wp_reset_postdata(); ?>
<?php else : ?>
<p><?php esc_html_e( 'There is no post to display' ); ?></p>
<?php endif; ?>
get_sub_field方法“返回来自Repeater或Flexible Content field循环的特定子字段值”-这些实际上是子字段吗?@04FS是的,因为事件详细信息来自字段类型组,而不是Repeater
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php echo get_permalink(); ?>">
<h4><strong><?php the_title(); ?></strong></h4>
</a>
<?php
if ( get_field( 'dafed_promo' ) == 1 ) :
$post_object = get_field( 'choose_dafed' );
if ( $post_object ):
$post = $post_object;
setup_postdata( $post ); ?>
<?php if ( have_rows( 'event_details' ) ) : ?>
<?php while ( have_rows( 'event_details' ) ) : the_row(); ?>
<div class="event-info">
<p></p>
<?php // Load field value and convert to numeric timestamp.
$unixtimestampdafed = strtotime( get_sub_field( 'event_time_and_date' ) );
?>
<div class="date">
<div class="month"> <?php echo date_i18n( "M", $unixtimestampdafed ); ?></div>
<div class="number"><?php echo date_i18n( "d", $unixtimestampdafed ); ?></div>
</div>
<p>
<strong>Vreme: </strong> <?php the_sub_field( 'event_time' ); ?><br>
<strong>Lokacija: </strong><?php the_sub_field( 'event_location' ); ?><br>
<strong>Organizator: </strong> <?php the_sub_field( 'event_organizer' ); ?>
</p>
</div>
<span class="path"><strong><a>
<?php echo get_the_author(); ?></a></strong> / <?php echo get_the_date(); ?>/
<strong>
<?php
$post_id = get_the_ID();
$post_categories = get_the_category( $post_id );
foreach ($post_categories as $category) {
echo '<a class="category-name">' . $category->cat_name . '</a> ';
}
?>
</strong>
</span>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php endif; ?>
<a href="<?php echo get_permalink(); ?>" class="btn btn-border">Pročitaj više</a>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php else : ?>
<?php if ( have_rows( 'event_details' ) ) : ?>
<?php while ( have_rows( 'event_details' ) ) : the_row(); ?>
<div class="event-info">
<p></p>
<?php // Load field value and convert to numeric timestamp.
$unixtimestamp = strtotime( get_sub_field( 'event_time_and_date' ) );
?>
<div class="date">
<div class="month"> <?php echo date_i18n( "M", $unixtimestamp ); ?></div>
<div class="number"><?php echo date_i18n( "d", $unixtimestamp ); ?></div>
</div>
<p>
<strong>Vreme: </strong> <?php the_sub_field( 'event_time' ); ?><br>
<strong>Lokacija: </strong><?php the_sub_field( 'event_location' ); ?><br>
<strong>Organizator: </strong> <?php the_sub_field( 'event_organizer' ); ?>
</p>
</div>
<span class="path"><strong><a>
<?php echo get_the_author(); ?></a></strong> / <?php echo get_the_date(); ?>/
<strong>
<?php
$post_id = get_the_ID();
$post_categories = get_the_category( $post_id );
foreach ($post_categories as $category) {
echo '<a class="category-name">' . $category->cat_name . '</a> ';
}
?>
</strong>
</span>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php endif; ?>
<a href="<?php echo get_permalink(); ?>" class="btn btn-border">Pročitaj više</a>