Site logo

Archived topic

Is There a Way to Create An Element Rule for a Non-Public Taxonomy?

3 replies · Started by Samuel on March 10, 2022

Viewing posts 1–4 of 4

I have a custom taxonomy that is currently set to "public = false" because it's not displayed on the website. It is simply used to select certain content to be displayed in different parts of the website. I want to create a display element that is selected when a custom post type also has a specific value in this custom taxonomy. However, the element display rules only show taxonomies that are marked public. Is there any way to create a display rule for a non-public taxonomy?

Hi Samuel,

You can try this:
1. Do not set a location in your block element.

2. Add this PHP snippet to display the element on the single custom post type page with certain custom taxonomy value:

add_filter( 'generate_element_display', function( $display, $element_id ) {
    if ( 100 === $element_id  && is_singular( 'cpt_slug' ) && has_term('green','color' )) {
        $display = true;
    }

    return $display;
}, 10, 2 );

Replace 100with your element id,cpt_slug with your custom post type slug, green with your custom taxonomy value, color with your custom taxonomy slug.

@Ying - Thank you this is great!

You are welcome :)

This archived topic is closed to new replies.