I've created a taxonomy (let's call it tax). I need to limit what a user can see. The users can't edit anything, just read the blog. If it was just setting what they could see once, I'd probably just create a new user role, but what they will be viewing will change frequently.

So for an example:

   user1 can view tax1, tax4
   user2 can view tax3
   user3 can view tax1, tax2

Then next week that all changes (kinda like checking out a movie or a book then returning it).

How can a make sure that the users can't view any other taxonomies than the ones they're assigned?

I'm hoping there is a function that I just haven't found that is something like:

    echo "You're not permitted to view this";
    //Continue with showing page...

I already have things set up so that in their user profiles I can assign them their taxonomies. So on the frontend when the page pulls up I can check which taxonomies they can see. But they can still navigate to other taxonomies. If they see that they're on http://website/tax1/ then they could just type in http://website/tax2/ and see the other taxonomies.

This has to be done on an individual user basis and not assigned to a role since there will be so many different users and so many different taxonomies.

Sorry I can't provide a live example; it's being developed locally and it contains some sensitive info.

If I need to clarify anything I'm more than happy to.

Thanks for the help!

  • How are you storing what users can view what taxonomies? Usermeta? – mor7ifer Jan 28 '12 at 23:35
  • Yes, through usermeta. – john Jan 29 '12 at 0:01

How about something like if( in_array( $current_tax, get_user_meta( $user, 'legal_taxonomies', true ) ) ) You can get the current taxonomy information using get_term_by(). This operates on the assumption that you're storing the available taxonomies as an array, but is easily changed for any storage method.

  • Dude! You are my hero! I've been battling this for hours. I had to modify things just a bit to get it working, but it's your answer that got me going down the correct path. Here's what I went with: $slug = $wp_query->query_vars['taxonomy']; $value = get_term_by('slug', $slug, 'taxonomy')->term_id; $a_terr = get_user_meta( $user, 'user-meta', true ); and then the check: if(!in_array($value,$a_terr)){//kick them out<br/>}else{}. Again, thank you! – john Jan 29 '12 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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