I'm building a website for a french school.

My problem : part of the website content will be private. Me and some other specified users will publish private posts (posts that only the 600 already-registred users will be abble to see). But an excerpt of those posts (small photo+some text) shall be visible to any visitor in the Home page. As soon as I set a post category to "Private" (using Role Scopper plugin), all excerpts of this post category, on the Home Page, also stop being displayed.

So what I'm trying to do is : "wheter or not a Post is set to private, force this excerpt to be displayed anyway". Note that I'm not a web dev, I just know a tiny bit of php.

Any plugin / hooks / code to put in the loop or somewhere else ?

Already tried this solution, inserting the code in the index.php loop, but it didn't change anything.

I'm using a theme (campus theme) that had been largely re-arranged (css-wise).

EDIT Here is the template code of the homepage:

<!-- CONTENT -->
    <div class="content <?php echo $layout_class; ?>">
        <div class="content-inner">                     

        <!-- THE POST LOOP -->  
        <?php while ( have_posts() ) : the_post();?>
            <!-- Page Title -->
            <div class="page-title-breadcrumbs">
                <h1 class="page-title"><span><?php the_title(); ?></span></h1>
                    <?php if(get_custom_field('show_breadcrumbs') == 'Yes') : ?>
                        <div class="breadcrumbs">| <?php echo get_breadcrumb(); ?></div><?php endif; ?>
            <hr class="page-title-hr" />

            <!-- Page Caption Section -->
            <?php if(get_custom_field('page_caption') . get_custom_field('page_background_image')) : ?>

                <div class="<?php echo $layout_class; ?>" id="section-page-caption">
                    <?php get_template_part( 'includes/element', 'page-caption' ); ?>
                </div >

            <?php endif;?>  

            <!-- THE PAGE CONTENT -->
            <?php the_content(); ?>

            <!-- PAGINATION for Multiple pages -->
            <?php wp_link_pages('before=<br /><div id="page-links"><span>Pages:</span>&after=</div><hr />&link_before=<div>&link_after=</div>'); ?>             

            <!-- COMMENTS SECTION -->

            <?php comments_template(); ?> 
            <div class="hidden"><hr /><?php wp_list_comments('type="comment&avatar_size=64'); ?></div>
            <?php next_comments_link(); previous_comments_link(); ?>
            <div class="hidden"><?php comments_template( '', true ); ?></div>
            <!-- COMMENTS-SECTION -->

        <?php endwhile; ?>  

    <!-- /CONTENT -->

Thank you for your attention, gentlemen

and sorry if bad english ;)

  • The solution you linked to should work. I would say try another template other than index.php. Is there a front-page.php or home.php template in your theme?
    – ngearing
    May 19, 2015 at 2:36
  • I'm sure I found the right template, since when I put an echo before the loop it shows on the homepage. Though, I don't really know WHERE to put the code inside the php part. I edited my Post to add the code. Could you drive me on where I should put the code to solve my pb ?
    – Aubry
    May 19, 2015 at 8:09

1 Answer 1


You could add this to your themes functions.php file. This adds private posts to the initial loop on the homepage only.

 * Include private posts in homepage loop
function show_private_posts_on_homepage($query) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_status', array( 'publish', 'private' ) );

add_action('pre_get_posts', 'show_private_posts_on_homepage');

Depending on your theme, you might need to swap out $query->is_home() with $query->is_front_page()

  • Actually, I might remove my answer - I hadn't read the explanation of Role Scoper, so this may not help. May 19, 2015 at 6:17
  • I'm using Divi template and wanted private posts to show up in the blog module. Adding your solution to my functions.php did the trick. I replaced if ( $query->is_home() && $query->is_main_query() ) by if (!$query->is_single()) so that it would work everywhere where I use the blog module. Thanks! Aug 28, 2017 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.