Skip Navigation

[Résolu] Filter Posts based on related post.

This support ticket is created Il y a 6 années et 6 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Ce sujet contient 15 réponses, a 3 voix.

Dernière mise à jour par Mike Il y a 6 années et 5 mois.

Assisté par: Shane.

Auteur
Publications
#902582

So now that I have created and imported my post relationships thanks to the help in this thread: https://toolset.com/forums/topic/many-to-many-post-relationship-configuration/

I want to be able to filter the "Voters" CPT based on "Elections" they voted in.

I would like to be able to select the following criteria:

Election: (Related Post)
Primary Party: (a custom field in the "Votes" Intermediary post)

So for example:

List voters that have voted in the following Elections:

Statewide General Election 2014
Statewide General Election 2012
Statewide Primary 2014 - With the Option of "R" (from the intermediary custom field)
Statewide Primary 2012 - With the Option of "R" (from the intermediary custom field)

I have been able to create a search filter based on custom fields in the Voter CPT, but not sure how to do this with related posts and haven't found a tutorial that describes it.

#902805

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - assuming that you are using latest Toolset Beta plugins, actually, You can set your view to filter by custom field of intermediary post when your view is set to query by intermediary post type. By doing this you can still able to output the fields or related posts.

Filtering by fields of a related post itself is not yet supported but is in the pipeline for development and we are planning to focus on this feature development after the next major release which is scheduled to happen by next week.

If you can give me more clear explanation what exactly you want to display exactly at what page/post I can better guide you.

Following Docs may help you:
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/

#903123
untitled_page.png

Oh, this is frustrating, I just lost everything I typed as the site went down for update. Let me try to explain again.

I have the following setup, a many to many relationship between the CPT’s “Voters” and “Elections” with an intermediary post “Votes”

Looking at the attached, very rough wireframe mockup, this is what I am trying to achieve on a page.

The top left box is the search filter for “elections” used selects what voters they want to display based on the related election they voted in.

Only primary elections have an associated party. This is a custom field in the intermediary post and only populated on primary elections, other elections it is left blank. This is the center box and it’s connection to the election is shown by the red outline.

The last filter is the top left box and represents custom fields in the “Voters” CPT. I have been able to accomplish this type of search filter as it is relatively straightforward.

Results are displayed below in the table.

Hope this makes more sense of what I am working on.

#903964

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

I will be handling this ticket going forward.

Could you let me know which version of Types you are using ?

Also would you mind providing me with admin access tot he site so that I can take a deeper look at this for you ?

Thanks,
Shane

#904075

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

Unfortunately you won't be able to filter by the intermediary CPT , however you will be able to filter by the parent post by adding an ancestor filter.

Thanks,
Shane

#904081

I may be able to get around this by creating individual posts for the two types of primaries instead of having them as custom fields.

That said, Is there a tutorial or documentation that explains how to use an ancestor filter?

#905118

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

I'm not sure if i'm following correctly here.
"I may be able to get around this by creating individual posts for the two types of primaries instead of having them as custom fields."

Could you explain a bit further here for me.
Thanks,
Shane

#905618

The most important thing for me right now is the second part of the previous post as I need to be able to filter the Voters by which Elections they have voted in.

"Is there a tutorial or documentation that explains how to use an ancestor filter?"

But to answer your question, are the posts I currently have in regards to "Elections" CPT.

Presidential Election 2016
Statewide Primary 2016 (intermediate post custom field is used to Identify party)
Presidential Primary 2016 (intermediate post custom field is used to Identify party)
Statewide General Election 2014
Statewide Primary 2014 (intermediate post custom field is used to Identify party)
Presidential Election 2012
Statewide Primary 2012 (intermediate post custom field is used to Identify party)
Presidential Primary 2012 (intermediate post custom field is used to Identify party)

So, since I cannot filter by intermediary post type, I may have to add additional posts in the "Elections" CPT to incorporate the primary election information something like this:

Presidential Election 2016
Statewide Primary 2016 - Republican
Statewide Primary 2016 - Democrat
Presidential Primary 2016 - Republican
Presidential Primary 2016 - Democrat
Statewide General Election 2014
Statewide Primary 2014 - Republican
Statewide Primary 2014 - Democrat
Presidential Election 2012
Statewide Primary 2012 - Republican
Statewide Primary 2012 - Democrat
Presidential Primary 2012 - Republican
Presidential Primary 2012 - Democrat

It will increase the number of "Election" CPT posts by 5 but it will eliminate the need for "Party Type" custom field from the Votes intermediary CPT. Hope this makes sense now.

#907510

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

Sorry for the delay in response as we recently released major updates and we had bugs coming in.

I'm able to look at this now.

I'm assuming this is a Many to Many relationship and not a One to Many correct?

So it should be possible to use views to add the ancestor filter. With the ancestor filter you're able to filter by the parent post so it lists all the children of that selected parent.

Do you have a view setup for this so that I can see what has been done so far?

Thanks,
Shane

#909120

It is a many to many realtionship.

I have been able to add the ancestor filter to my search block.

However, the issue I seem to be having is that if I select more than one filter it seems to be returning a result that matched "any" of the selections not "all" of the selections.

For example

I want voters that voted in all these elections:

Statewide Primary 2016
Statewide Primary 2014
Statewide Primary 2012

If I check the boxes for all three, I get the result where someone may have voted in any of those elections but not necessarily all of them.

Joe Smith voted in Statewide Primary 2016
Bill Rogers voted in Statewide Primary 2014 and Statewide Primary 2012
Jane Watson voted in Statewide Primary 2014
Angela Jones voted in Statewide Primary 2016, Statewide Primary 2014, and Statewide Primary 2012

Angel Jones was the voter I was looking for as she voted in all of the elections.

Hope that makes sense.

Is there a setting them I have missed that allows the search filter criteria to return all selections instead of any?

#909538

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

I understand what you mean, so you only want to filter the posts for someone who has voted in all 3.

Unfortunately no its actually not possible because of how the filter is meant to work.

Thanks,
Shane

#909542

OK, this is problematic because it is critical to the functionality of what I need to achieve.

I am thinking I will need to create a Taxonomy "elections" I can have more than one "Election" checked for each voter and I do believe I can then filter in the way I need?

Are there any issues I may run into with this method?

#909573

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

I believe this will still be an issue.

The reason is because single filters are usually done using an OR and not an AND so if a taxonomy is used I suspect the same issues will be present.

An AND can only be done through 2 different filters.

Thanks,
Shane

#909580

Is there any way to achieve what I am trying to accomplish?

#910700

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Robert,

The only way i see this possible is with the use of some custom code to do this.

Thanks,
Shane