Skip Navigation

[Résolu] Post Form Categories: How to Only Display select Categories?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 réponse, has 2 voix.

Last updated by Nigel Il y a 1 an et 9 mois.

Assigned support staff: Nigel.


Tell us what you are trying to do?
I would like to add a category field to my Post Form but only display certain categories. I initially tried hiding the unwanted ones with CSS, but that code is overwritten. Is there a way to designate which taxonomies should display? I would also like to add labels above the category groups so this would be useful to break them apart.

If I use the taxonomy field, they categories do not auto assign to the posts. I want the selection in the form to designate the category of the post.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link



Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Hi Lilian

I only just had time to get to this this morning.

I've produced a fairly generic code sample which you can use to restrict what terms are included in a taxonomy field in a form, which can also be used for a taxonomy search filter in a View.

It uses the WordPress get_terms filter, and to avoid it applying everywhere you must specify the page(s) where the Form and/or Views are inserted, as well as providing the taxonomy slug and an array of term slugs to either blacklist or whitelist as required.

 * Blacklist or whitelist terms in a taxonomy form field or View filter
function tssupp_restrict_terms( $terms, $taxonomies, $args, $term_query ){

    // 1. pages where form (or search View) is inserted
    $pages = array( 118, 137 );

    // 2. which taxonomy (slug)
    $taxonomy = 'status';

    // 3. add terms to blacklist *OR* whitelist, not both
    $blacklist = array();
    $whitelist = array( 'archived', 'completed' );

    if ( is_page( $pages ) && $taxonomies[0] == $taxonomy ) {

        if ( !empty( $blacklist ) ) {

            foreach( $terms as $key => $term ){
                if ( in_array( $term->slug, $blacklist ) ) {
        } elseif ( !empty( $whitelist ) ) {

            foreach( $terms as $key => $term ){
                if ( !in_array( $term->slug, $whitelist ) ) {
    return $terms;
add_filter( 'get_terms', 'tssupp_restrict_terms', 10, 4 );