Site logo

Archived topic

Tag ID

9 replies · Started by Tawna on May 19, 2022

Viewing posts 1–10 of 10

Hi there,

thats correct, that snippet will exclude any post from the blog/homepage that has a specific tag.
you can select any of your tags in Dashboard -> Post -> Tags - if you select a tag and edit it you will find its ID is in the browser URL field.

Thank you.

So the tag is 100172 and when I entered that same tag # last night I couldn't get it to work. Can you please add it for me below how it should be so I can check it again and see what I am doing incorrectly? Mine lookes like this and I am using the Code Snippets plugin: ... array( 100172 ) ); ...

function exclude_posts( $query ) {
if ( $query->is_home() ) {
$query->set( 'tag__not_in', array( 13 , 26 ) );
}
}
add_action( 'pre_get_posts', 'exclude_posts' );

So your code would be this:

function exclude_posts( $query ) { 
    if ( $query->is_home() ) {  
        $query->set( 'tag__not_in', array( 100172 ) ); 
    } 
} 
add_action( 'pre_get_posts', 'exclude_posts' );

David,

This is exactly how I also had it - but it is not excluding these posts.

Thanks,

Tawna

Can you link me to the Tag archive ? ie. the tag you want to exclude

I am not trying to exclude it on the static pages - I attached the pages I thought were requested. I am trying to take the posts with the tag 'credit card contacts' from showing up in queries, for example, on this page.

https://smartmomhq.com/manage-money/

The code method i provided only applies to the main query loop that is found in the Blog and Archive templates.
It won't apply to the /manage-money page as it is built using the WordPress Query Loop block.
That particular block is pretty new and is really limited on its filterable options.

However we are currently Alpha testing GenerateBlocks 1.5:
https://generateblocks.com/generateblocks-1-5-dynamic-data-query-loops-image-blocks/

And our Query Loop block will allow you to include and exclude different taxonomies directly in the editor.

We expect a release candidate of the plugin in June.

This archived topic is closed to new replies.