首页 > 解决方案 > 仅在存档中显示作者帖子的帖子(不包括 admin 和 editor )

问题描述

我的默认代码显示管理员、编辑和作者的所有帖子。但我只想显示作者的帖子。

<?php get_header(); ?>

    <?php
        if( have_posts() ):
            while( have_posts() ): the_post();
                the_title();
                the_content();
            endwhile;
        endif;
    ?>

<?php get_footer(); ?>

标签: wordpress

解决方案


试试这个。

<?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; ?>

推荐阅读