• If a user is logged in, the Categories widget should include private categories if (like for all categories) there is a post for that category. But that isn’t the case. For example, I have a new post in a private category. When I’m logged in, the post itself appears just fine and the private category label appears below the post, but the category is ABSENT in the widget listing.

    If a private category is visible in a post for a logged in user, why shouldn’t the widget also include that private category? Of course, when not logged in, neither the private post nor the widget listing for that category should appear.

    This should be easy to fix.

    (Theme: Beaver Builder, but this is not a theme function.)

    Thanks!
    Steve

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, @zocios. Are you using a specific plugin which makes it possible to have private categories, and if so, which one?

    Or are you actually talking about private posts which have simply been assigned to a particular category which you use for all such posts (and thus, consider it to be “private” based on that)?

    Thread Starter zocios

    (@zocios)

    Hi, @girlieworks. Thanks for the reply!

    I’m talking about private posts that have been assigned to a particular category. I’m not using a plugin to create a private category.

    So, you’re right – my description was confusing because I was confusing my terminology. (I’m new to WP programming — only on my second site. Still learning! ??)

    So, to try to be more clear: When I have a private post assigned to a particular category, say “Events”, and a user is logged in and therefore able to read the private post, why shouldn’t “Events” appear in the Categories widget? (Obviously, this only applies if there hasn’t been another recent post that’s assigned to the “Events” category that’s isn’t “Private”, because in that case “Events” would appear in the Categories widget.)

    Thanks again.

    Hi, again, @zocios.

    When I have a private post assigned to a particular category, say “Events”, and a user is logged in and therefore able to read the private post, why shouldn’t “Events” appear in the Categories widget?

    Because that’s not how the Categories Widget is designed to work “out of the box”. ??

    But some custom PHP code like this (when placed in your child theme’s functions.php file) should make the “private” category show up in the Widget (as well as any other place where the wp_list_comments function is being used):

    add_filter( 'widget_categories_args', 'show_private_post_cats' );
    
    function show_private_post_cats( $args ) {
    
      if( current_user_can( 'read_private_posts' ) ) {
    	$args['hide_empty'] = 0;
      }
    
      return $args;
    }

    Hi,

    girlieworks, That filter worked beatifully on the categories widget!
    Do you know of a way to do the same thing for Archives widget (include private posts for logged in users with right capabilities)?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Categories marked "Private" do not appear in Categories widget’ is closed to new replies.