Archived topic
Tag ID
9 replies · Started by Tawna on May 19, 2022
I believe the php code on this page will exclude tags from a specific query. However, where do I find the tags for my site (examples are given.) Thank you.
https://docs.generatepress.com/article/exclude-tags-from-posts-page/
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
Is this what you need, David?
https://staging.smartmomhq.com/tag/credit-card-contact/
I am trying to exclude from this page specifically, although it is fine if the tag is excluded across the site:
https://staging.smartmomhq.com/manage-money/
Thanks
Tawna
Hi Tawna,
The page you linked is static page not the default blog page, the PHP snippet won't work on static pages.
You are using a WP query loop block to insert the posts, Unfortuanly GP has no control over this block.
I would suggest using Query loop block of GenerateBlocks 1.5: https://generateblocks.com/generateblocks-1-5-dynamic-data-query-loops-image-blocks/
You can exclude posts within the block settings.
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.
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.