自定义 Post 类型实例全部使用相同的特色图片(第一个)

Custom Post Type Instances All Use Same Featured Image (The First)

我在 functions.php 中按以下方式在 Wordpress 中定义了自定义 post 类型:

add_theme_support('post-thumbnails', array('post', 'my_custom_post_type' ));


function my_custom_post_type()
{
    $labels = array(
        'name' => _x('MyCustomPostTypes', 'post type general name'),
        'singular_name' => _x('MyCustomPostType', 'post type singular name'),
        'add_new_item' => __('Add New MyCustomPostType'),
        'edit_item' => __('Edit MyCustomPostType'),
        'new_item' => __('New MyCustomPostType'),
        'all_items' => __('All MyCustomPostTypes'),
        'view_item' => __('View MyCustomPostType'),
        'not_found' => __('No MyCustomPostTypes found'),
        'not_found_in_trash' => __('No MyCustomPostTypes found in the trash'),
        'parent_item_colon' => '',
        'menu_name' => 'MyCustomPostTypes'
    );
    $args = array(
        'labels' => $labels,
        'description' => 'MyCustomPostType Here',
        'public' => true,
        'menu_position' => 5,
        'supports' => array('title', 'editor', 'thumbnail'),
        'has_archive' => true,
    );
    register_post_type('my_custom_post_type', $args);
}

add_action('init', 'my_custom_post_type');

当我创建 MyCustomPostType 的第一个实例时,一切看起来都很棒。每个后续实例也是如此——除了,所有这些后续实例上的特色图像都与第一个相同。所有其他数据都是正确的,并且页面的 Edit MyCustomPostType 视图中显示的特色图像是正确的。所以我真的很困惑。

我正在像这样遍历实例:

<?php
    while ($my_custom_post_types->have_posts()) {
       $my_custom_post_types->the_post();
?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></li>
<?php
    }
?>

当我显示特定的 post( the_permalink 的目标)时,我是这样做的:

<section id="content" role="main">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h1><?php single_post_title(); ?> </h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-3">
                <figure>
                    <?php the_post_thumbnail('medium'); ?>                                                              
                </figure>
            </div>
            <div class="col-lg-9 text">
                <?php the_content(); ?>
            </div>
        </div>
    </div>
</section>

但正如我所说,此调用在每种情况下都会检索 MyCustomPostType 按时间顺序排列的第一个实例的特色图片。

对问题的任何见解或我应该在 wp_posts table 中查看的内容表示赞赏。

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

        <div class="row">
        <div class="col-lg-12 text-center">
            <h1><?php single_post_title(); ?> </h1>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-3">
            <figure>
                <?php the_post_thumbnail('medium'); ?>                                                              
            </figure>
        </div>
        <div class="col-lg-9 text">
            <?php the_content(); ?>
        </div>
    </div>          

<?php endwhile; ?>