我最近的帖子中有一些数字值,这些数字值是通过高级自定义字段放置的。我希望能够将数据从帖子中拉到另一个页面中。这可以通过ID轻松完成: https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/ 但我无法完成的工作就是从最近的职位中撤出。 ACF支持网站没有提及最新消息。
<?php
$args = array( 'numberposts' => '1' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
// acf query in here. not included for brevity.
endif;
}
wp_reset_query();
?>
答案 0 :(得分:1)
摘自https://developer.wordpress.org/reference/functions/wp_get_recent_posts/上的食典(稍作修改):
<?php
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 1, // Number of recent posts thumbnails to display
'post_status' => 'publish' // Show only the published posts
));
foreach($recent_posts as $post) : ?>
<a href="<?php echo get_permalink($post['ID']) ?>">
<?php echo get_the_post_thumbnail($post['ID'], 'full'); ?>
<p class="custom-class"><?php echo $post['post_title'] ?></p>
</a>
<?php
$custom_field = get_field('custom_field_name', $post['ID']);//for ACF fields
?>
<?php endforeach; wp_reset_query(); ?>