Site logo

Archived topic

Filter dynamic data

3 replies · Started by Kees on September 21, 2022

Viewing posts 1–4 of 4

Hi,

Is there a way to limit dynamic data. When we use gutenberg with dynamic data. We would like to show specic dynamic tags. But not all tags. Is there a way to filter the tags in dynamic data.

See attached video.

Regards,
Niek

Hi Kees,

You'll need to create a Shortcode to retrieve for instance just the first tag. Example code:

add_shortcode( 'display_single_tag_term', function() {
	//$termslist = get_the_term_list( get_the_ID(), 'tag', '', ', ');
	$terms = get_the_terms( get_the_ID(), 'post_tag');
	$term_link = get_term_link( (int) $terms[0]->term_id, 'post_tag');
	$term_name = $terms[0]->name;
    ob_start();
    // Start your PHP below
  
    echo '<a href="'.$term_link.'" rel="post_tag" class="custom-single-tag">'.$term_name.'</a>';
  
    // End your PHP above
    return ob_get_clean();
} );

You can then place this Shortcode [display_single_tag_term] in a Shortcode Block within a Container Block. Then, style the Container Block instead.

Nice, thank! i will try that.

You're welcome Kees!

This archived topic is closed to new replies.