edit.php all post not working

时间:2019-06-30 作者:thamarai selvan

我正在使用publish press插件创建自定义帖子状态我将所有帖子状态更改为public,使用

register_post_status(
    $status->slug,
    [
        \'label\'       => $status->name,
        \'public\'   => true,
        \'exclude_from_search\'       => true,
        \'show_in_admin_all_list\'    => true,
        \'show_in_admin_status_list\' => true,
        \'_builtin\'    => false,
        \'label_count\' => _n_noop("{$status->name} <span class=\'count\'>(%s)</span>",
            "{$status->name} <span class=\'count\'>(%s)</span>"),
    ]
);
所有帖子显示在前端,但编辑。php all post页面不工作它没有显示与自定义帖子类型相关的所有帖子,这也影响了woocommerce

1 个回复
最合适的回答,由SO网友:thamarai selvan 整理而成

当我输入所有自定义帖子状态时,终于找到了解决方案public 它将post\\u类型声明为默认post as global so applied filter,以根据URL中请求获取的类型更改全局post\\u类型


function publishPress_allPost_pre_get_posts( &$wp_query )
{
    if ( is_admin() && array_key_exists( \'post_type\', $_GET ) ) {
        $wp_query->set( \'post_type\', $_GET[\'post_type\'] );
        add_filter( \'the_posts\', \'publishPress_allPost_the_posts\', 10, 2 );
    }
}

function publishPress_allPost_the_posts( $posts, &$wp_query )
{
    $wp_query->set( \'post_type\', $GLOBALS[\'post_type\'] );
    return $posts;
}