Skip Navigation

[Résolu] hierarchy mix? relationship? not sure what to use and how..

This support ticket is created Il y a 4 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 18 réponses, has 2 voix.

Last updated by Ido Angel Il y a 4 années et 9 mois.

Assisted by: Waqar.

Auteur
Publications
#1299149

hey,

I have an index of writers. among other things, they have won awards. A writer can win many award, in many years. for example:
pulitzer, 1988
pulitzer, 1989
noble, 2000
booker, 2000
pulitzer, 2001
also, other writers can win these awards, of course. so in "booker", year "2000" - you can have 3 winning writers.

I want to be able to:
1) filter according to prize (all writers who have won the "booker")
2) filter according to years (all writers who have won an award in 1989)
3) filter according to both: writers who have won the booker in 1989

how would i go about that?

if i user hierarchial taxonomies (parent is "booker", child is "1989"), the problem is that "1989" child will be different under each parent (1989 for booker will be different than 1989 for noble).
if i use relationships (create a post type of "awards" which will be related to "writers", and "years" which will be related to "awards") - how would i enable a writer to win booker both in 1989 and 1991?

confused :\

any ideas?

thx!!

#1299215

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

Thank you for waiting.

Thinking this through, what you need is a new central post type which will act as a reference point or an anchor.

You can register a new custom post type, let's call it "Award Entry" ( or whatever you prefer ).

This new custom post type "Award Entry" will have:

- A one-to-one relationship with "Writer" post type.

- A many-to-many relationship with the "Award" and "Year" post types.
( note: you can also choose to use static select type fields for "Award" and "Year" selection, attached to this "Award Entry" post type. In that case you'll not need "Award" and "Year" post types and their relationship with "Award Entry" )

When you'll be adding a new "Award Entry" post, you'll have the option to select the writer, the award name and the year for it.

And the actual search view with the required filters can be set to show "Award Entry" posts and not the "Writer" posts.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1299243

hey Waqar!

Intereting! 🙂

let me review this:

So my "award entry" cpt will have 2 select fields, 1 for the award title (or institute), the other for the year.
then i can create entries and name each "institute name + year" (booker 1988, for example) - according to the selected fields.
Then I can attach each one of them to a writer via 1-2-1 relationship - or maybe i need many-2-many relationship, because a lot of writers can win the same prize at the same year, and a single writer can win many prizes.

then, in search, i add a filter for relationship between writer and award entry.

right?

but:
1) how would i show "writers who have won the booker across history"?
2) how would i show "writers who have won awards in the year 1989"?

thx!!
ido

#1299323

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

Thanks for writing back.

> Then I can attach each one of them to a writer via 1-2-1 relationship -
> or maybe i need many-2-many relationship, because a lot of writers
> can win the same prize at the same year, and a single writer can win many prizes.

- Each "Award Entry" post will reflect an individual "win" and therefore it will need to exist as a unique instance. As a result, it won't matter if the multiple writers are winning the same award in the same year or the same writer wins multiple awards in a year or even his life.
( as long as a separate record in form of an "Award Entry" post has been added )

It is important to also note that while keeping a record for every win through an individual "Award Entry" post, more than one writers shouldn't be attached to a single "Award Entry" post. For example, if "Writer A" and "Writer B" both have won the "Booker" award for the year 1988, you'll need to add two posts and not one.

- Writer A - Booker - 1988
- Writer B - Booker - 1988

In this case, I'm not recommending to attach multiple writers to a single win ("Award Entry" post) because originally the search reference point was writers, which we had to shift to "Award Entry" post, to have data that is more searchable/filterable.

If more than one writers will be attached to a single "Award Entry" post, and you'll show some search results from this post type through a view, you'll have no way to shortlist, which "one" of those writers should be shown on the front-end and you'll have to either show all attached or none.

And I apologize for the confusion earlier as the relationship between a writer and an award entry should be of type one-to-many and not one-to-one. This is because a single writer can have multiple wins ("Award Entry" posts), but a single "Award Entry" post can't have more than one writer.

This can't be one-to-one because then you'll be restricted to attach only one win ("Award Entry") to an individual writer, which is not what we want.

And this can't be many-to-many because, as we discussed above, a single win shouldn't be attached to more than one writer.

Once you've stored the data in this structure, showing these results would become very simple:

1) how would i show "writers who have won the booker across history"?

- Query filter would be to show all "Award Entry" posts, where the award is "booker".

2) how would i show "writers who have won awards in the year 1989"?

- Query filter would be to show all "Award Entry" posts, where the award year is "1989".

Please remember, that if you've reached to an "Award Entry" post in results, you can easily show the info of its attached writer.

regards,
Waqar

#1299341

Thx Waqar!

I'm more confused now 🙂

You write:

"a single writer can have multiple wins ("Award Entry" posts), but a single "Award Entry" post can't have more than one writer" - and - "And this can't be many-to-many because, as we discussed above, a single win shouldn't be attached to more than one writer" - But a win CAN have more than 1 writer. 2 writers can win booker in 1988.

About the search:

I have a search to filter out writers, not "wins". there are many filters there apart from awards: year of birth, writing subjects, genres etc. Into this, I need to add an "awards" filter which will filter both awards and award years. Is this possible?

thx!

#1299419

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

I'm sorry my message resulted in further confusion. I'll be happy to clarify this further.

I understand that difference that we're having is on the meaning of the word "Win". Let's look at it from a different angle.

Suppose that whenever a writer wins an award, a special honorary shield is given to him/her. Even when more than one writers are sharing the same award in the same year, each one receives his/her own honorary shield. This means that despite each of them have won the same award, they will have their unique honorary shields, physically.

Now let's say that each "Award Entry" post on your website will not reflect the award's win, but it will reflect each honorary shield. Of course, each shield will hold info about the award's name, the year and the name of the writer who has won it.

Hope this makes it more clear.

> I have a search to filter out writers, not "wins". there are many filters there
> apart from awards: year of birth, writing subjects, genres etc. Into this, I need
> to add an "awards" filter which will filter both awards and award years. Is this possible?

- I'm afraid, the way search filters work, you won't be able to perform the search on "Writers" post and the "Award Entry" posts through the same view.

You'll have to use two separate views:

- One that will search for the Writer post type, with filter fields like the year of birth, writing subjects, genres etc.

- The other one that will search for the "Award Entry" post type, with the filter fields like Writer, Award and Year.

If you'd like to achieve all this using the same view. you'll have to make sure that whenever a Writer post is attached to an Award Entry post, same custom fields values for year of birth, writing subjects, genres etc are also copied from that Writer post into that "Award Entry" post.

But this arrangement will become very challenging because if you'll change any field value for example "year of birth", in writer post, then you'll have to make sure to update it manually in all connected "Award Entry" posts too.

regards,
Waqar

#1299453

thx for clarifying Waqar 🙂

I get that she "win" embodies both award title, award year, and writer. but isn't the writer taken from the relationship?i mean - if i have many to many relationship, i can attach different writers to the same award and vise versa: I can have a "win" with custom fields "booker" and "1988", and attach different writers to it, and I can attach to a specific writer two "wins", like "booker 1988" and "noble 2001". right? so i still can't see why it must be a 1-1 relationship.

about the search - hmmm... problematic. I must have everything in one search and must filter writers. That's the whole point.

Won't this be possible with simple repeatable field group? A group named "awards" with fields "award title" and "award year"?

cheers
ido

#1299469

maybe:

create a taxonomy of "awards" with custom field "year"?

#1300171

Hey again,
I'm sure there's a clever way somewhere to achieve this.
maybe hierarchial taxonomies? repeatable group of fields? maybe create a hidden field in writers to match the fields in "win"?
thx for the help!
Ido

#1300679

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

Thank you for waiting and I apologize for the delay.

I had to perform several tests, to come with a suggestion that will cover all the initial requirements that you've shared:

> I want to be able to:
> 1) filter according to prize (all writers who have won the "booker")
> 2) filter according to years (all writers who have won an award in 1989)
> 3) filter according to both: writers who have won the booker in 1989
> 4) the search system should work through a single view

- First, the approaches that won't work:

a). My suggestion to include a new reference post "Award Entry" won't work because then Writer's data will be saved separately and it won't be possible to perform a search through a single view.

b). Repeating field group in the main Writer post, won't work, because the data in such fields is stored as a separate hidden child post type and you won't be able to apply the search filters on both post types through the same view.

The approach that can actually work is by using some custom taxonomies, attached to the "Writer" post type:

a). Award Years ( term examples: 1989, 1990, 1991, 1992, 1993, 1994 and so on ).
b). Award Names ( term examples: pulitzer, noble, booker and so on ).
c). Awards ( term examples: pulitzer (1988), noble (2000), booker (2000), pulitzer (2001) and so on ).

This arrangement will mean more data/taxonomy term management work for the website's admin, but once each writer will have correct terms assigned to him/her, you'll be able to perform the filtering that you're looking for.
( i.e. search by year, search by award or search by a specific award in a specific year )

I hope this helps.

regards,
Waqar

#1300763

Thx for the effort Waqar! Greatly appreciated.
How would I go about constructing the search then?
And how would I assign terms to a writer who has won:
Booker 1988
Noble 1988
Booker 1989
?

#1301269

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

Thanks for writing back.

> And how would I assign terms to a writer who has won:
> Booker 1988
> Noble 1988
> Booker 1989

- If a Writer has won these awards, this is how you'll assign the taxonomy terms to his/her post:
Screenshot: hidden link

> How would I go about constructing the search then?

- You'll be able to construct the search, like this:

a). In the Query Filter section, these the filters for these taxonomies will look like this:
Screenshot: hidden link

b). In the Query Filter section, these the filters for these taxonomies will look like this:
Screenshot: hidden link

c). And this is how these filters will show on the front-end:
Screenshot: hidden link

Here is how they link to the initial requirement:

1) filter according to prize (all writers who have won the "booker")
Screenshot: hidden link

2) filter according to years (all writers who have won an award in 1989)
Screenshot: hidden link

3) filter according to both: writers who have won the booker in 1989
Screenshot: hidden link

Aditional tip: it would make sense to make sure only one of these 3 filter options are shown to visitors, at one time. For that you can add a custom HTML select field with options "Search by Award", "Search by Year" and "Search by Award and Year".

The 3 taxonomy filters can be hidden to start with and when a visitor selects any option from this new custom HTML field, the respective taxonomy filtering field can be shown, using custom script.

This setup will work very similar to what we have discussed in the previous threads:
( the only difference would be that in this current case, you won't have to manupulate the backend query, through "wpv_filter_query" function )
https://toolset.com/forums/topic/allow-frontend-user-to-change-any-to-all/
https://toolset.com/forums/topic/allow-frontend-user-to-change-any-to-all-closed-by-mistake/

regards,
Waqar

#1301421

thx for the detailed answer Waqar!

however...
I can still get wrong results this way.
if writer A won booker in 2000 and noble in 1999,
and writer B won booker in 1999 and noble in 2000,
when i search in the first 2 filters "booker" and "1999" i get in the third filter "booker 1999" (ok) AND "booker 2000", because the first guy won a prize in 1999 (even though it's not booker).

am i thinking wrong?

#1301451

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

The essence of this approach is that although these 3 filters are available in the search form, they should be used one-at-a-time.

I can see the value of having the options to filter the results based on these filters individually (one-at-a-time), but I can't think of a case, where I would need to make a selection in more than one of those taxonomy filters, in a single search.

To elaborate, if I would want to see all writers who have won a particular award ( your requirement 1 ), I would only select its name from "Award Names" filter and leave the other two fields.

Likewise, if I'd like to see all writers, who have won an award in a particular year ( your requirement 2 ), I'll only select it from "Award Years" filter and leave the other two.

And lastly, if I'd like to see a list of writers who won a specific award in a specific year ( your requirement 3 ), I'll only select the combined value from the "Awards" filter and leave the other two.

I can understand that a visitor can mistakenly select values in more than one of these taxonomy filters in a single search, but that is specifically why I included the "Aditional tip" section in my last message. In summary, you can hide all these 3 filters initially and only show one-of-them, based on the selection made through a new HTML select field in the search form, that will determine if I'd like to search by a year, by an award or by both.

Hope this clarifies.

regards,
Waqar

#1301531

Ah - I get you. When you said "it would make sense to make sure only one of these 3 filter options are shown to visitors, at one time" I mistakenly took that for appearing one after the other (like in "show only available options"), now I get I need to actually never show MORE than one, which makes sense.
Since I would allow users to change the custom HTML select from "search by years" to "search by prize" to "search by prize in year" - I would have to make sure on each change the values of the other filters are reset, so that they won't interfere with the search (if someone, for example, first chose "by year 1999" then decided to switch to "by prize noble", I need to reset the "by year 1999" option no nothing. right?)
Thanks for all the help!!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.