Skip Navigation

[Resolved] View: show ads only from current child

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

Problem:
The user would like to filter a custom post type by to relationships with other custom post types.

Solution:
Currently, Toolset allows filtering with ONLY ONE relationship.
For the user use-case, it is preferable to use a taxonomy for on the custom post types. That way it can be used on the filter.

This support ticket is created 4 years, 8 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.

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: Africa/Casablanca (GMT+01:00)

This topic contains 9 replies, has 2 voices.

Last updated by RaulS6474 4 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#1569249

Hi,

There are 4 types of post type and relationships:
1) "Provincia" = State
2) "Municipio" = Town
3) "Codigo postal" = Postal code
4) "Anuncio" = Ad

- There are 4 relationships:
- many ads for each postal code (one to many) - [slug: codigo-postal-anuncio]
- many postal codes for each town and many towns for each postal code (many to many) - [slug: municipio-codigo-postal]
- one state for each town (one to one) - [slug: provincia-municipio]

I still need to create:
- user register form where it indicates State > Town > Postal code. All ads from that user would have that info (postal-code / town /state). _Note that some postal codes belongs to different towns, and towns have different postal codes (as usual)

--- Question:

On town ("municipio") post type single template: hidden link I only want to display ads that belongs to that town ("municipio")

That page is using "Anuncios de municipio" view, and I am not sure how to achive that...

--- ** Please let me ad login info **

#1569809

Hello and thank you for contacting the Toolset support.

I tried a similar case on a test server and I was able to show the ads from the postal codes that are linked to a town, check it here hidden link
I have the following:
State1:
- Town1: Linked to Postal Codes (CODE1, CODE2)
- Town2: Linked to Postal Codes (CODE3, CODE2)
Postal Codes:
- CODE1: has ad Ad-1
- CODE2: has ad Ad-2
- CODE3: has ad Ad-3
I was able to do it by creating the following:
1. First, you need to make sure that the intermediary post type for "towns-postal_codes" relationship is visible on the admin menu. Go to Toolset->Post Types, edit your intermediary post type and make sure that " show_in_menu" is checked in options.
2. Create a view that will show ads from the relationship of the postal code. It should have a query filter on the relationship to The current post in the loop. Check this screenshot hidden link
3. Create a view that will display codes from the relationship of towns. It should have a query filter on the relationship to The post where this View is shown. Check this screenshot hidden link
4. Use the view created in (2) inside the loop of the view created in (3).
5. In the Content Template for towns, add a view block and use the view created in (3)

You can check it on the test server with the credentials: admin / admin123
Please note, that on the test server, I assigned the content template only to the town "Town2".

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

#1572389
Screenshot 2020-04-02 at 17.13.18.png

Hi Jamal,
thanks for your help. We are going on good direction, I have implemented it. — But as I told you on intro post: some postal codes belongs to multiple towns.

If you check hidden link you can check that first ad belongs to "28492, El Boalo, Madrid" - The issue here is that 28492 is also a postal code for Manzanares el Real (current page)

So we need to check that all ads imported belongs to current town.

Any idea?

---
ps: maybe is interesting to create a Town - Ad relationship and load it directly?

Ads are going to have user's profile location, that is set on its profile page with 3 selects related between them: state > town > postal code (each parent shows possible childs). So maybe it's possible to feed [ postalcode - ad ] [ town - ad] [ state - ad ] relationships? (not done that form yet)

This may be a better idea I beleive, as ads would be all ordered by date, mixing postal codes. — Let me know if all this is possible please

#1572487

I think that the most straight forward solution is to create a One-to-Many relationship Town<>Ad, then filter for the siblings' ads under the parent town. Here is a similar case https://toolset.com/forums/topic/displaying-sibling-posts-of-a-child-post-in-blocks/

Otherwise, I do not see how to get the correct town from an ad only by its parent Postal Code. If the parent Postal Code is linked to two towns, then how could we distinguish between them and get the correct town. This can be possible with a custom field on an ad that stores the town, or by a relationship One-to-Many(Town<>Ad).

I hope this makes sense. Let me know if you have any doubts/questions.

#1576861
Screenshot 2020-04-07 at 12.07.57.png

Hi Jamal,
I have created a Town (one) - Ad (many) relationship, edit all ads to fill that relationship, created a view with query filter: " Filter by post relationship or repeatable fields group owner " choosing that new relationship and "The post where this View is shown". Content selection was ads.

I edit Town's template and added the new view, but it shows all ads...

hidden link

Any idea? Want to check admin?

#1577167

Please fill the private details fields after a full site backup. I would like to access the admin area of your site for further checking. Please check the following links for more details about our private information sharing policies.

#1581319

Everything seems correct, however the view display all ads.
Please allow me to take a Duplicator copy for further debugging locally.

#1581423

Sure, thanks Jamal

#1585327

Hello and my apologies for the late reply. It took me sometime before figuring out the bottom of the issue. I should have figured it out early.

Currently, there is a limit of one relationship in Toolset Views query filters. This means, that we cannot filter the ads on both relationships with Towns and with Postal Codes.

In fact, if you remove the following filter from the view search section, the results include only the ads under the town in its single page.

[wpv-control-post-relationship ancestors="codigo-postal@codigo-postal-anuncio.parent" url_param="wpv-relationship-filter"]
			[wpv-control-post-ancestor type="select" default_label="..." ancestor_type="codigo-postal@codigo-postal-anuncio.parent"]
[/wpv-control-post-relationship]

This being a limit, we can work around it by using an additional taxonomy or custom field.
I would suggest dropping the Custom Post Type "Códigos postales" and using a taxonomy instead. The taxonomy will be used for "Anuncios" and "Municipios".

I'll remain at your disposal.

#1586795

Yep that solved the problem!
Hmmm I would think about postal codes and taxonomies, thanks Jamal!!