小编quo*_*web的帖子

Wordpress,查询后更改了全局帖子

我正在开发一个插件。在这个插件中,我创建了一个自定义帖子类型“toto”。

在管理页面中,我使用以下帖子 ID '82' 编辑自定义帖子元素。在这个页面中,我启动了一个查询来检索具有另一个 post_type 的元素:

$featured_args = array(
'post_type' => 'other_type',
'post_status' => 'publish'    
);

// The Featured Posts query.
$featured = new WP_Query( $featured_args );

// Proceed only if published posts with thumbnails exist
if ( $featured->have_posts() ) {
    while ( $featured->have_posts() ) {
        $featured->the_post();
        if ( has_post_thumbnail( $featured->post->ID ) ) {
            /// do stuff here
        }
    }

// Reset the post data
wp_reset_postdata();
}
Run Code Online (Sandbox Code Playgroud)

这样做全局 $post 改变了。它不再是 id 为 82 的帖子,而是来自查询的最新帖子元素。

我认为 wp_reset_postdata() 函数将允许我检索我当前的 $post。我也试过 wp_reset_query() …

php wordpress

1
推荐指数
1
解决办法
613
查看次数

标签 统计

php ×1

wordpress ×1