WordPress.org

Ready to get started?Download WordPress

Forums

Archive widget for private posts (3 posts)

  1. eddudley
    Member
    Posted 2 years ago #

    Hi,

    The archive widget in WordPress does not show private posts, even if these are available to the logged in user.

    Is there any way to:

    a) include all private posts in the count, even if a user can't access them

    or

    b) include private posts which are visible to the user in the count?

    If there is a plugin with a widget with this functionality, that would also be great but I can't seem to find one.

    Thanks,

    Ed

  2. eddudley
    Member
    Posted 2 years ago #

    For anyone else struggling with this, I found an answer. Put this in your theme's functions.php

    function customarchives_where( $x ) {
    	return $x . " OR (post_type = 'post' AND post_status = 'private')";
    }
    
    if ( is_user_logged_in() ) {
        add_filter( 'getarchives_where', 'customarchives_where' );
    }

    If a user is logged in, the archives widget will now include private posts.

    Comments from any wordpress pros as to whether this is the best way to do this are more than welcome!

  3. sqalg
    Member
    Posted 1 year ago #

    Hello
    Thks for this sharing

    But When I put your code, inside my functions.php file ,I doesn't have the result expected with all widgets plugged on my right menu.
    These widgets are included with the basic version of WordPress 3.5.1 or with the jetpack package.
    I precise that all my articles are private
    For example, I can't see the last articles or in the calendar of articles: there is no traces of my articles arranged by date

    May be , do you have any suggestions ?

    Thk
    SQALG

Topic Closed

This topic has been closed to new replies.

About this Topic