mjut Posted November 3, 2021 Share Posted November 3, 2021 I am building a web site with a blog / posts section. With each post I create I can add tags. That is happening with a page reference field. For each new tag a new tag (page) will be created. On an "archive" page, I want to list all tags with this code: <ul> <?php $tags = $pages->find("template=tag, sort=title"); foreach ($tags as $tag) { ?> <li><a href="<?php echo $tag->url ?>"><?php echo $tag->title ?></a></li> <?php } ?> </ul> Simple as that, it works as expected. All tags used anywhere in my posts are listed. (yaaay!) But: When creating a new post without publishing, new tags be created and will listed on my archives pages. How can I modify my code to exclude all tags that are associated with unpublished posts? Cheers Stephan Link to comment Share on other sites More sharing options...
Zeka Posted November 3, 2021 Share Posted November 3, 2021 Also you can use owner selector like template=tag, tags.owner.template=post, limit=10 Where 'tags' is your page reference field used in blog post template and 'post' is the name of this template. 1 Link to comment Share on other sites More sharing options...
mjut Posted November 3, 2021 Author Share Posted November 3, 2021 @Zeka Thank you tons! Yet again, it amazes me how simple Processwire is. I went for the owner selector. Sorry, I did not know about this. The functional code looks like this: <ul> <?php $tags = $pages->find("template=tag, tags.owner.template=post, sort=title"); foreach ($tags as $tag) { ?> <li><a href="<?php echo $tag->url ?>"><?php echo $tag->title ?></a></li> <?php } ?> </ul> As simple as that. I looked it up in the docs, but did not find it – but there is a blog post about Owner Selectors: https://processwire.com/blog/posts/processwire-3.0.95-core-updates/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now