wordpress - 未登录用户的 WP_query 私人帖子(在 WordPress 5.7 中更改)
问题描述
我正在使用此代码查询所有私人帖子:
$wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'private', 'posts_per_page'=>-1));
在 WordPress 5.7 之前,此代码显示所有私人帖子,即使对于未登录的用户也是如此。然后我只是通过 the_content 过滤器隐藏了这个端口上的链接。正在帮助编写带有交叉链接的大量帖子的功能。但现在这段代码不起作用:
function no_working_links_list( $content ) {
$wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'private', 'posts_per_page'=>-1));
if ( $wpb_all_query->have_posts() ) :
while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
$linker = get_permalink();
$content = no_working_links( $content, $linker );
endwhile;
wp_reset_postdata();
endif;
return $content;
}
add_filter( 'the_content', 'no_working_links_list' );
function no_working_links( $content, $linker ) {
$pattern = '~(<a href="' .$linker. '">)([^<]*)(</a>)~';
$content = preg_replace($pattern, '$2', $content);
return $content;
}
也许有人有想法?
解决方案
发现,上面示例中的错误不在 wp_query 中。从 WP 5.7 开始,私人帖子的 get_permalink($ID) 将显示:
https://example.com/pretty/link/如果用户登录
和
https://example.com/?p=100如果用户未登录
推荐阅读
- powershell - 如何过滤 EventLog 以每天获取一个日志 - PowerShell
- android - 使用 Android Camera2 为 Surfaces 配置不同的 FPS
- python - 在 apply 中访问 groupby 值
- vba - 当我使用 DoCmd.OpenForm 时运行时关闭
- node.js - 使用 node.js 脚本重命名文件名的一部分
- javascript - 从 SQL 中以 JSON 格式检索多个记录集
- domain-driven-design - 是否可以在构建单体应用时实施 Scrum?
- python-3.x - 如何将'符号添加到字符串
- android - 错误:Gradle 任务 assembleDebug 失败,退出代码为 1 - 在颤振项目中更改包名称后
- angular - 如何实现 Angular 路由动画?