Jump to content

Building a list of 'tags' currently in use


a-ok
 Share

Recommended Posts

Forgive me if this question already exists somewhere... but struggling with the following.

I have a parent > child page system of events (Events > Event 1), and for each event (page) there is a repeater of dates (to allow multiple dates). On each event there is also a PageReference field for the client to select 'tags'. This is also a parent > child structure (Tags > Music). I am wanting to create a tag filter for the front end so ideally I'd like to return all the tags, in use by events (as these tags are also used by other sections) that's dates haven't passed yet.

I current have the following which is returning all the event pages still in date...

$events = $pages->find("template=events-detail, events_detail_dates.events_detail_dates_start_date>today");

I think thought I would have to loop through these pages, grab the tags, then build each result into an array and use remove any duplicates (would $a->unqiue work?) so I end up with a clean list. I'm just not 100% sure that's the best way to proceed... can anyone confirm?

Thanks!

Link to comment
Share on other sites

@Robin S's ConnectPageField is perfect for this use case. You need to create another Page Reference field, say `tagged` add it to tag template. When you set up the module, when you add a tag on a page, the page will be added to tag's page reference field. Then you can just use $pages('template=tag, tagged.count>0') to find all used tags.

15 minutes ago, oma said:

would $a->unqiue work?

Not really, it works on identical objects, not objects with identical values. See this for a potential solution:

and this one

 

Link to comment
Share on other sites

Thanks, abdus. Looks like this module may be just the trick.

My favourite part? 

Quote

Now when you add "Orange buffoon" to Related for "Donald Trump", "Donald Trump" is automatically added to Related for "Orange buffoon".

 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Apologies to bring this back up but I'm having a slight issue. This seemed to be working for me before but for some reason has stopped.

I am using @Robin S's ConnectPageFields and my selector is

template=tags, tagged.template.name=events-detail, tagged.count>0, sort=name

It should return all tagged pages which use X template and count is > 0. I swear this was working before but now when I dump out the query it's written as

["selectors"]=>
  string(66) "template=tags, tagged.id=0, tagged.count>0, sort=name, status<1024"
}

If I put 'tagged.template=' in the selector (obviously doesn't work but it's returned the same but when I use multiple sub selectors (tagged.template.name=) it seems to change it to tagged.id=0

Any thoughts?

Link to comment
Share on other sites

Matching by tempate name in a PageReference field is working for me:

$items = $pages->find("test_page_reference.template.name=basic-page");

Could it be that you have no template named "events-detail" or no pages using that template selected?

Incidentally, how did you dump the selector to get the selector string that PW converts to? Looks like a useful debugging trick.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...