wordpress - 仅在存档中显示作者帖子的帖子(不包括 admin 和 editor )
问题描述
我的默认代码显示管理员、编辑和作者的所有帖子。但我只想显示作者的帖子。
<?php get_header(); ?>
<?php
if( have_posts() ):
while( have_posts() ): the_post();
the_title();
the_content();
endwhile;
endif;
?>
<?php get_footer(); ?>
解决方案
试试这个。
<?php if ( is_user_logged_in() ):
global $current_user;
wp_get_current_user();
$author_query = array(
'posts_per_page' => '-1',
'author' => $current_user->ID
);
$author_posts = new WP_Query($author_query);
while($author_posts->have_posts()) : $author_posts->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php endwhile;
else :
// Do Something
endif; ?>
推荐阅读
- visual-studio-code - 切换分支的快捷键是什么?
- ckeditor5 - 如何将光标移动到ckeditor5中的文本末尾
- jmeter - Jmeter for loop http请求 - 并行
- object - 想在任何地方自动选择特定窗口(对象克隆) 11.2
- android - 在 webview 上隐藏本机 textSelectHandleLeft:Android
- yii2 - yii2 作曲家更新上的“UnexpectedValueException”
- c++ - 表示日期的字符串并对其进行转换
- javascript - 如何正确使用 Three.js FBXLoader?
- swift - 全局禁用某些方法上的 SwiftLint multiline_arguments
- java - 严重:GET 的异步超时 [使用 Spring MVC 4.3.x、Java 8、Tomcat 7 流式传输大量数据]