Skip Navigation

[Resolved] private taxonomy

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem: Taxonomy terms that should only be visible inside the WP admin area are being output in the post element's HTML classes. How can I make a taxonomy private so that no one on the front-end of the site can see these terms.

Solution: Setting a taxonomy's public flag to "false" will make the taxonomy hidden in the wp-admin area, so this setting cannot be utilized to restrict visibility of a taxonomy to wp-admin users only. Use custom fields for internal classification instead of taxonomy terms, or write a custom PHP solution that filters your taxonomy terms from the post class names array provided by the function get_post_class().

Relevant Documentation: https://codex.wordpress.org/Function_Reference/get_post_class
https://codex.wordpress.org/Function_Reference/register_taxonomy#Example_Private_Taxonomy

This support ticket is created 7 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 10 replies, has 2 voices.

Last updated by Gretchen Louise 7 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#487170

I am trying to: create a taxonomy that is private--i.e. in no way visible, via archives, post content, post meta, post classes, etc. to a user who is not logged in.

I visited this URL and see that it is possible in WordPress: https://codex.wordpress.org/Function_Reference/register_taxonomy#Example_Private_Taxonomy

I expected to see: the public or private option when creating a new Taxonomy in WP Types.

Instead, I got: nothing that indicated public or private.

Thank you.

#487220

Hi there, I don't think that the 'public' flag can be used to conditionally display posts or taxonomies to only logged-in users. In this case, 'public' indicates taxonomy visibility and management on the front-end of the site or in the wp-admin area. Non-public indicates taxonomy management and assignment only in the code of your theme or plugin. As the WordPress documentation states:

"public (boolean) (optional): Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users."

and

"It will be available to use internally by your plugin or theme..."

This indicates that no user, whether logged-in or not, will be able to see a non-public non-rewritable taxonomy either on the front-end of the site or in the admin area. No one will be able to create terms for this taxonomy, or assign those terms to any post, from the admin area. This can only be accomplished in code, and then the stored information can only be accessed in code.

So I don't think that you can restrict a taxonomy to logged-in users in the way you are expecting with a non-public, non-rewritable taxonomy.

On the other hand, Toolset Access provides the ability to limit read access of specific content or groups of content to specific users or groups of users. It also provides some taxonomy and taxonomy term management restrictions within the admin area for different users. Here's some information about the features Toolset Access provides:

https://toolset.com/documentation/user-guides/setting-access-control/

Please let me know if I can be of further assistance with this, or if you would like more specific information about what Access can accomplish.

#487245

Okay, what I want to do is create a Taxonomy for internal content auditing and content statuses. I'd like to have tags such as "social media shares scheduled" and "outdated content to update" that wouldn't show to our readers, but that we could easily access inside the WP Admin area. Does that make sense? What option would I use for that?

Further, for some reason I do not have Access Control in my Toolset. Is that a separate upgrade?

Thank you for your help!

#487272

Okay sure, this is actually possible without Access.

1. In the WordPress admin area, go to Toolset > Taxonomies and create a new taxonomy. For simplicity I'll call it "Internals"
2. Enable any Post Types you would like to categorize with your Internal terms
3. Open up the Options panel of the Taxonomy editor page. If it's not visible, scroll up to the top of the page and click "Screen Options" and make sure you have it selected for display.
4. Uncheck every checkbox in the Options panel except "show_ui", since you want to be able to see these terms in the wp-admin area.
5. Re-save your Permalink settings (Settings > Permalinks, click Save Changes)
6. Create terms in the new taxonomy for your internal use, like "irrelevant" or "outdated"
7. Apply these terms to your posts like any other taxonomy terms
8. Do not output the taxonomy terms in any View, Content Template, Layout, or other theme .php file.

I've seen some buggy things happen if you attempt to modify an existing Taxonomy's options, so be sure to create a new Taxonomy with the correct options instead of updating an existing one. Let me know how that goes for you.

FYI: Access is a separate plugin, but it comes as part of your purchase if you chose a package like "Basic" "Agency" or "Lifetime" when you bought Toolset. In this case, you should be able to download the plugin from your wp-types.com account page, then install it and activate it on your site.

If you only purchased individual components, like just "Views" then Access would be a separate purchase.

#487273

I found and installed Access Control but it still does not solve my problem.

As an example, I created a "Content Status" taxonomy.

The latest post on my site (hidden link) shows the exact content status taxonomy that the post has in the source code:
<article class="post-39938 post type-post status-publish format-standard has-post-thumbnail category-inspirational tag-perseverance content-status-in-welcome-automation entry gs-1 gs-odd gs-featured-content-entry" itemscope itemtype="hidden link">

Is there a way to keep a taxonomy hidden from public view?

Thank you!

#487274

Christian, it looks like you were replying at the same time I was. I'll try that and let you know. Thank you!

#487277

Christian, I tried creating a brand new taxonomy called Internal Status, with only show_ui checked, and re-saved the permalinks. But unfortunately, it still allows for external view (i.e. hidden link) as well as view within source code (internal-status-test-internal-status entry ).

Unfortunately, Access only allows for control of who can create/change the taxonomy, not who can view it.

I could make all the slugs of the taxonomies numerical so no one would be able to tell on the front end. But it seems odd that this is impossible. I actually went searching for a solution with Toolset because the Content Audit plugin had this same issue (https://wordpress.org/support/topic/content-audit-post-statuses-publicly-visible/).

#487284

I see what you mean. All related taxonomy terms are output as part of the WordPress function get_post_class():
https://codex.wordpress.org/Function_Reference/get_post_class

I assume your theme uses the get_post_class function to render these class names, and removing a custom taxonomy's terms from this list would require custom PHP code that filters the class name array.

As an alternative, you could use custom post fields. You could add a custom Post Field Group to your posts, and include checkboxes to apply your custom tags there. The unfortunate thing is that the easy-to-use taxonomy interface, with type-aheads and easy taxonomy term creation, is not going to be available. You would have to manually create all the tag options and include them in a Post Field Group. Is this something you think could work for your needs?

#487295

Thank you, Christian. It seems I'll just have to use numerical class names for now as I can't get anything like this to work at the moment, either:

add_filter('body_class', function (array $classes) {
if (in_array('internal-status', $classes)) {
unset( $classes[array_search('internal-status', $classes)] );
}
return $classes;
});

Custom fields could do the trick, too, I suppose, but I'd rather the ease of a Taxonomy. Really appreciate your help! Thank you!

#487313

Agreed, it's a shame there's not a better way to handle this in WordPress with taxonomy options. We should recommend it to them as a feature request 🙂

#487319

For sure. Thanks so much for your help!

The forum ‘Types Community Support’ is closed to new topics and replies.