Skip Navigation

[Resolved] Choosing Parent Posts or Relationship Intermediary to display a View

This thread is resolved. Here is a description of the problem and solution.

Problem:

Query related posts on many-to-many relationship, and filter by custom fields of intermediate post type.

Solution:

You can setup a view, query the posts of intermediate post type, and filter the result by custom fields of intermediate post type.

Relevant Documentation:

https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

This support ticket is created 3 years, 10 months ago. 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 – 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/Hong_Kong (GMT+08:00)

This topic contains 28 replies, has 3 voices.

Last updated by AlimB3245 3 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1904783
Screen Shot 2021-01-14 at 11.13.12 AM.png
Screen Shot 2021-01-14 at 11.12.53 AM.png
Screen Shot 2021-01-14 at 11.12.44 AM.png
Screen Shot 2021-01-14 at 11.12.32 AM.png
Screen Shot 2021-01-14 at 11.12.15 AM.png
Screen Shot 2021-01-14 at 11.11.58 AM.png
Screen Shot 2021-01-14 at 11.11.49 AM.png

Tell us what you are trying to do?
I have a 2 custom posts ie
1) OPTICIANS
2) YOU&EYE AWARD EVENTS

And my end result for the view is this one..

hidden link

Now in the YOU&EYE AWARD EVENTS I create a post for every year ie 2016, 2017, 2018... 2021.
There's a many-to-many relationship between OPTICIANS and YOU&EYE AWARD EVENTS.. and in the intermediary posts I have these custom fields as 'checkboxes'
1) Participating Category
2) Nomination Category
3) Winner Category

In each of the above the award categories are mentioned ie Best Eyewear Retailer, Best Marketing Initiative, etc.. so all of them have the same named checkboxes... when opticians participate the checkboxes for the participating category would be checked (they could participate in multiple categories) and when some of they are nominated then the checkboxes in the nomination category would be checked and finally the winner category.

Here's the screenshots of the Relationship and the intermediary posts for an easier understanding.

My question is
When I create a view in a PAGE, what do I use in the CONTENT SELECTION? Do I use OPTICIANS or do I Use YOU&EYE AWARD EVENTS and create a post relationship query or do I use You&Eye Award Events To Opticians Intermediary Posts?

The condition for displaying the OPTICIANS who are participating would be to display those opticians that are in the intermediary posts where any checkbox in PARTICIPATING CATEGORY is checked for the EVENT in 2021..

Further instead of ANY checkbox, I'd like to know how to specify a particular checkbox (category)..

Another related question
I have a Event Start Date custom field in the events custom post .. it's in dd-mm-yyyy format I think.. but when I filter it to show only the events for 2021, how do I choose only the YEAR?

Please advise as I am very confused and I need to ensure that we have the best way to query this result for best performance.

I think you would need to have access to really understand the workings.. so do let me know if you need to have access and I'll be happy to provide you super admin access to check the setup.. I feel that would be much faster and more efficient.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link

#1905307

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

"When I create a view in a PAGE, what do I use in the CONTENT SELECTION?"

Can you clarify what exactly you want to display?

Assuming you want to create a page specific to 2021, the context will need to be the 2021 YOU&EYE AWARD EVENT post. But then what do you want to display?

It may be that you need multiple Views depending on how you want to organise what you want to show, but we need more details to be able to advise you.

Regarding filtering a date field for a particular year, dates are stored as timestamps (i.e. a particular moment in time, recorded in seconds since 1 Jan 1970), so you would need a filter BETWEEN 1 Jan 2021 and 31 Dec 2021.

#1905939
Screen Shot 2021-01-15 at 7.31.37 AM.png
Screen Shot 2021-01-15 at 7.29.15 AM.png
Screen Shot 2021-01-15 at 7.26.49 AM.png

Hi Nigel

Thanks for the prompt update.. and apologies for not being very clear about the requirement...

Can you clarify what exactly you want to display?

This is the page that displays all Opticians

hidden link

I want a similar view that displays all opticians with a filter applied that chooses only those opticians that have participated in a specific event. This specific event post ... can it be selected as a specific post during the query?.. this would be great.. then I don't need to choose the custom post based on date as I was trying to do achieve it based on dates.

Assuming you want to create a page specific to 2021, the context will need to be the 2021 YOU&EYE AWARD EVENT post. But then what do you want to display?
So as I mentioned above, I think the date does not matter if we can filter down to a specific custom post. Please do confirm if this screenshot is the right way.. I've selected OPTICIANS in the content selection with this query.. but I am not getting any result..

https://toolset.com/wp-content/uploads/tmp/Screen_Shot_2021_01_15_at_7.26.49_AM.png

Regarding filtering a date field for a particular year, dates are stored as timestamps (i.e. a particular moment in time, recorded in seconds since 1 Jan 1970), so you would need a filter BETWEEN 1 Jan 2021 and 31 Dec 2021.
Please check screenshot link below and advise what option should I first choose whenever I choose a date field to filter.. string, date, datetime?..

https://toolset.com/wp-content/uploads/tmp/Screen_Shot_2021_01_15_at_7.29.15_AM.png

and once I do that.. what do choose in the next field in the screenshot provided below? I would like to only filter based on YEAR ie 2016, 2017, etc.. this may not be relevant to the current ticket as we might go the specific post way to filter but I'd still appreciate a response to this as it's something I've always wondered how to use..

https://toolset.com/wp-content/uploads/tmp/Screen_Shot_2021_01_15_at_7.31.37_AM.png

Thanks again.. and I hope I've been able to convey the requirement clearly this time.

Have a nice day..:-)..

Regards,
Alim

#1906141

Hello,

There are lots of questions in this thread, according to our support policy, we prefer one ticket one question.

For the first question:
This specific event post ... can it be selected as a specific post during the query?.

It is not clear, which one is the specific event post?
In your screenshot:
https://toolset.com/wp-content/uploads/2021/01/1905939-Screen_Shot_2021_01_15_at_7.26.49_AM.png
you have already specific a post in the "Query Filters", where do you want to specific the post?

#1906175

Hi Luo

Thanks for the update..:-)..

Yes, I chose the specific post as I was experimenting.. didn't realise I had that option.. so I wanted to check if it was right..

However it didn't result in the opticians showing up..

Also other than the fact that the specific post is selected I need to further filter down to the Participation Categories in the relationship..

https://toolset.com/wp-content/uploads/2021/01/1904783-Screen_Shot_2021_01_14_at_11.12.32_AM.png

either ANY checkbox is checked in the Participation Category or a specific checkbox (like Best Eyewear Retailer) is checked .. need to know how to filter both ways (ANY participation category or SPECIFIC participation category)

Regards,
Alim

#1906215
using-this-comparison.JPG

I am trying to answer the questions one by one:
Q1) so I wanted to check if it was right.
As the screenshot you provided above, that is built-in feature of Toolset plugins, so if you need such kind of feature, then use it correctly, you can follow our document to setup the relationship filters:
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

Q2) However it didn't result in the opticians showing up..
Are we talking about these? You did not get the expected results in front-end?

If it is, you can debug it in your website like these:
1) Remove all other filters, test again
2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

Q3) I need to further filter down to the Participation Categories in the relationship..
I assume "Participation Categories" is a custom checkboxes field, and you are going to filter the results by this checkboxes field, you can follow our document to setup the filter
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/

You can find and select the "Participation Category" field in the custom search form, then tweak on option "Using this comparison", see my screenshot: using-this-comparison.JPG

#1906249

Hi Luo

I'll try your methods suggested for Q1 and Q2...

but I think for Q3 there's some confusion..

I don't need to filter in the front end.. I need the results to be shown after the query/filter is applied in the backend..

so the opticians that's listed in the front end are based on these 2 conditions
1) There is a relationship for the optician post with the event post.
2) ANY participation categories is checked or SPECIFIC participation category is checked.

Regards,
Alim

#1906313
Screen Shot 2021-01-15 at 2.40.05 PM.png

I think I managed to add a query to get the QUERY FILTERS sorted and I have the list of opticians that are related to events to a specific post..

Now I am adding a custom field filter (screenshot attached).. and I know how to manage to filter or a specific category.. I would choose a 'string' then 'constant' and type the database value..

https://toolset.com/wp-content/uploads/tmp/Screen_Shot_2021_01_15_at_2.40.05_PM.png

But I want a non-specific filter.. ie any checkbox in the Participation Category (which is a custom field of multiple checkboxes) is checked..

https://toolset.com/wp-content/uploads/2021/01/1904783-Screen_Shot_2021_01_14_at_11.12.32_AM.png

Please advise..

Regards,
Alim

#1908771
cks.JPG

To avoid more misunderstandings, please elaborate the question with more details:

I want a non-specific filter.. ie any checkbox in the Participation Category (which is a custom field of multiple checkboxes) is checked..

I have tried these in my localhost with a fresh WP installation + the latest version of Toolset plugins, using below steps:
1) Create a custom checkboxes field "test-cks", with below options:
- Checkbox title 1, value: 1
- Checkbox title 2, value: 2
- Checkbox title 3, value: 3

2) Create a post "option 1+3", in field "test-cks", enabled two options:
- Checkbox title 1, value: 1
- Checkbox title 3, value: 3

3) Create a page, add a view block, in the custom search form, add field "test-cks", filter by:
Filter comparison: Compare value as a "string"
Using this comparison: Equal to
See my screenshot cks.JPG

Test above page, it works fine,

If I search with "Checkbox title 1" or "Checkbox title 3", I can get correct result:
post "option 1+3"

Is there anything missing?

#1908845
query-filters-toolset.png

Hi Luo

Thanks for the update..:-)..

I think we are both talking about 2 different things.. you are referring to SEARCH FILTERS and I am talking about QUERY FILTERS..

I am referring to creating a page that will display OPTICIANS but has 2 QUERY FILTERS applied..

One of the filter I have managed.. you can see it in this screenshot

https://toolset.com/wp-content/uploads/tmp/query_filters_toolset.png

It's the second part which is visible in the screenshot that I don't know how to filter..

I need to choose the PARTICIPATION category.. but in the dropdown it says STRING, NUMBER, BOOLEAN etc.. and I am not sure what to choose to filter 'ANY CHECKBOX' selection.. I know how to select a SPECIFIC checkbox selection though.. it would be to select STRING And then use the CONSTANT field to type in the database value.. but What if I just want to filter the selection based on any checkbox that was clicked?

I hope this makes it clearer. Sorry for the earlier confusion.. I can imagine how difficult it must have been for you to get what I am trying to convey...

Regards,
Alim

#1908871
cks2.JPG

Thanks for the details, you can setup the filter as below:
Select items with field:
PARTICIPATION category is a string in value1, value2

See my screenshot: cks2.JPG

#1909091
Screen Shot 2021-01-18 at 3.31.22 PM.png
Screen Shot 2021-01-18 at 3.38.54 PM.png

HI Luo

Thanks for the update.. so I assumes that when you choose string 'in' and then list all the database values, it works like an OR loop and lists out the filtered opticians.

So based on your suggestion I have this
https://toolset.com/wp-content/uploads/tmp/Screen_Shot_2021_01_18_at_3.38.54_PM.png

you will see that the opticians have been filtered based on a relationship and a custom field query with IN (as you had suggested)

Here's the You&Eye Events 20-21 custom post's relationship...

https://toolset.com/wp-content/uploads/tmp/Screen_Shot_2021_01_18_at_3.31.22_PM.png

you will notice that I have 3 opticians with the relationship and they all have some criteria in the Participation Category.. this should have resulted in 3 opticians being displayed on this page

hidden link

but I am not able to see any.. could you please advise what I am doing wrong?

Regards,
Alim

#1910055

Please provide your website credentials in below private message box, also point out the problem page URL, thanks

#1910231

I have tired the credentials you provided above, but get these error message:
The administrator has blocked your IP from accessing this website.

Please check it, make sure your website is ready for test and debug, backup your website first, then update here.

My IP address: 129.226.11.13

#1910241

Hi Luo

This seems to happen when I work with Toolset as I assume when you check a view if there's too many queries and they end up with 404 errors, there's a limit of 20 such hits within 300 seconds and the IP is blacklisted..

I have removed your IP from the blacklist and have added it to the whitelist so you should not have this issue now.

Please do check and confirm.

Regards,
Alim