[Support request] Hide parent taxonomy in List of terms of Dynamic text type

Home Forums Support [Support request] Hide parent taxonomy in List of terms of Dynamic text type

Home Forums Support Hide parent taxonomy in List of terms of Dynamic text type

  • This topic has 1 reply, 2 voices, and was last updated 2 years ago by Fernando.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2179300
    Takeru

    I want to hide the parent taxonomy in the List of terms of the Dynamic text type.

    Is there a way to do this?

    #2179330
    Fernando
    Customer Support

    Hi Marumoro,

    To achieve such, you can try adding this PHP snippet:

    add_filter( 'generate_dynamic_element_text_output', function( $term_output, $block ){
    	if ( 'terms' === $block['attrs']['gpDynamicTextType']  && 'd68a6ef2' === $block['attrs']['uniqueId']) {
    		
    		$terms = get_the_terms( get_the_id(), $block['attrs']['gpDynamicTextTaxonomy'] );
    
    						if ( is_wp_error( $terms ) ) {
    							return $block_content;
    						}
    
    						$term_items = array();
    
    						foreach ( (array) $terms as $term ) {
    							var_dump(substr_count(get_category_parents($term->term_id),"/"));
    							if(substr_count(get_category_parents($term->term_id),"/")>=2) {
    							if ( ! isset( $term->name ) ) {
    								continue;
    							}
    
    							
    								$term_items[] = sprintf(
    									'<span class="post-term-item term-%2$s">%1$s</span>',
    									$term->name,
    									$term->slug
    								);
    							}
    						}
    
    						if ( empty( $term_items ) ) {
    							return '';
    						}
    
    						$sep = isset( $block['attrs']['gpDynamicTextTaxonomySeparator'] ) ? $block['attrs']['gpDynamicTextTaxonomySeparator'] : ', ';
    						$term_output = implode( $sep, $term_items );
    
    						if ( ! empty( $block['attrs']['gpDynamicTextBefore'] ) ) {
    							$term_output = $block['attrs']['gpDynamicTextBefore'] . $term_output;
    						}
    	} 
    	return $term_output;
    },15,2);

    Kindly replace d68a6ef2 with the unique ID of your Dynamic Headline Block.

    How to get the unique ID: https://share.getcloudapp.com/z8uLkDEz

    Hope this helps.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.