0

I have a term that I'd like logged in admin users to see while they're browsing the site while keeping it hidden from the public.

I'd prefer to have it done at the lowest level possible, even so far as to prevent the term from showing up publicly with any of the functions (e.g wp_list_categories).

What's the best way to pull this off?

1 Answer 1

1

Currently we can not pass user_ID or user_role to wp_list_category() function, So it is not possible unless you use filter to do this, that is bit complicated so here I has a solution that does exact what you want without using filter.

<?php if ( current_user_can( 'manage_options' ) ) { /* A user with admin privileges */ wp_list_categories(); ? } else { /* A user without admin privileges */ wp_list_categories('exclude=4'); // 4 is id of category you'd like to hide } ?> 

Update -

I think using the get_category() function will be good idea, First grab all the categories as array and then show them as required.

<?php $categories = get_categories(); if(!current_user_can( 'manage_options' )) { $exclude = 4; // category ID to hide from non admin } else { $exclude = ''; } foreach ( $categories as $cat ) { if($cat->term_id != $exclude) { echo '<li>'.$cat->name.'</li>'; } } ?> 
3
  • This works for wp_list_category and I may accept it... How about get_the_term_list, though? Commented Aug 6, 2012 at 22:04
  • I updated my answer with simple example. Commented Aug 6, 2012 at 23:23
  • I like it - Not what I was thinking, but it is a simple answer that works! I'm accepting it. Commented Aug 20, 2012 at 20:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.