0

我最近的帖子中有数字值,这些值是通过高级自定义字段放置的。我希望能够将数据从帖子中提取到另一个页面。这可以通过一个 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();
     ?>
4

1 回答 1

1

来自https://developer.wordpress.org/reference/functions/wp_get_recent_posts/上的 Codex (稍作修改):

<?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(); ?>
于 2019-08-09T22:45:00.973 回答