Skip Navigation

[Closed] How do I display related posts that do not have a checkbox checked?

This support ticket is created 3 years, 11 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: Africa/Casablanca (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 3 years, 11 months ago.

Assisted by: Jamal.

Author
Posts
#1985479

Tell us what you are trying to do?

I have a custom post type called 'Commission'. It has a custom field for name, description and chair. There is a custom post type for 'Persons' (with fields for first name and surname). Many persons can belong to many commissions. The Commission-Person intermediary type has a custom field for Chair which is a check box. I want to connect Persons to being members of various commissions, and to select which person in each commission is the chair of that commission.
On the custom template for commission I want to list the name, description and the text field of the Chair person with the Text and Field widget so that I can add A.N.Other from the text and then append "(Chair)" after the name.
I then want to create a view that selects all the connected persons who are members of the commission but leave out the Chair so that it is not repeated. But I am having problems adding the query to filter out those connected persons who have the check for Chair ticked.

This is how I have thought of doing it. Basically I want to have a list of the Persons' names sorted alphabetically by their surname, but with the first person being the Chair... e.g.

Fr Matthew Charlesworth, SJ (Chair)
Fr A. N. Aaron
Fr A. N. Brown
Fr A. N. Charlie

etc.

Is there any documentation that you are following?

I've tried to read the documentation on views and relationships

Is there a similar example that we can see?

It's a similar problem to how I have Communities, with each Person linked to a specific community. The difference here is that one person can only be assigned to one community. But one person can belong to many commissions.

What is the link to your site?
hidden link

#1985571

Hello and thank you for contacting the Toolset support.

Let's take these results:
Fr Matthew Charlesworth, SJ (Chair)
Fr A. N. Aaron
Fr A. N. Brown
Fr A. N. Charlie

I believe you already created the first line, right? The person that has the checkbox ticked in the intermediary post. Right?

For the other lines, it will be a bit tricky, because you want to search using the checkbox in the intermediary post, but you want to order using the name fields in the Person custom post. That's not possible out of the box with Toolset views. But, I believe, we can find a way to do it.

Check this example on how to find the posts that have the checkbox unticked https://toolset.com/forums/topic/exclude-posts-with-enabled-checkbox-from-view/

The solution will depend on how you are creating the view:
- Using the block editor: Create a view of persons ordered by the name field. Then, we'll need to hook into the view's query and pass to it only the persons that have the checkbox unticked in the intermediary post of the relationship.
- Using the legacy editor: Create a view of persons ordered by the name field, that takes the persons' ID in a shortcode argument. Then create a view that will return the persons that have the checkbox unticked. Then we'll pass this view results as a shortcode argument. Check this particular reply, on how to return only the IDs of the post in the view's results https://toolset.com/forums/topic/exclude-posts-with-enabled-checkbox-from-view/#post-728149

If you are using the block editor, the custom code will need to hook into wpv_filter_query. And you can use either a view or the relationship API to get the persons' with unticked checkbox:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

I hope this helps. Let me know if you have any questions.

#1985631
Screenshot 2021-03-14 at 14.32.55.png
Screenshot 2021-03-14 at 14.31.04.png

I'm struggling to find out where to put these 'hooks'. I'm using the block editor.

#1985793

Hooks are actually custom code. It needs some programming skills. Read more about it here:
- https://toolset.com/documentation/programmer-reference/toolset-hooks/
- https://toolset.com/documentation/adding-custom-code/how-to-use-toolset-api-hooks-in-custom-code/
- https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

Would you like to produce a minimal example on this test site and I'll help you with it hidden link

You may also consider hiring one of our partners https://toolset.com/contractors/

The topic ‘[Closed] How do I display related posts that do not have a checkbox checked?’ is closed to new replies.