Skip Navigation

[Resolved] Display a post conditional to child post content

This support ticket is created 5 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by Christian Cox 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1233860

Hi,

I have an exhibition site with CPT "Venues" that is parent to "Exhibitions". I use views to display future, past and current exhibitions based on CF wpv-startdate and wpv-enddate.

Now I want to render a map with all Venues that have current exhibitions ( condition: (wpv-startdate <= NOW) AND (wpv-enddate >= NOW) ) as child posts. How can this be achieved?

If I'm correct, that the [wpv-found-count] won't help, as it doesn't allow for additional conditions? And to evaluate whether a view doing this conditional count is not possible with the Query filter in Views…

The current state can be seen on hidden link

Thank you for any hint!

#1233949

Hi, it's not possible to filter a View of post type A by custom fields applied to a related post type B, so you'll have to add a few steps to make this work. Here's the general idea:
- Create a View of Exhibitions and add the custom date field Query Filters to limit the date range for current Exhibitions
- In the Loop Editor, use the loop wizard to create a "list with separators" design. Use a comma for the separator and insert the post ID as the content.
- Place the View somewhere on the site as a test, and you should see a comma-separated list of post IDs for all the current Exhibitions.
- Create a View of Venues and add a post relationship Query Filter based on the Venue / Exhibitions relationship. The filter should be configured to respond to a shortcode attribute "wpvrelatedto". This will allow you to place a list of Exhibition IDs in the View's shortcode and the filter will return all the matching parent Venues.
- In the Loop of this View, add markers for each Venue along with any other information you want to display in the View results.
- Place the map shortcode somewhere outside the wpv-loop tags of either View.
- Place the Venue View shortcode somewhere on the site, and place the Exhibition View shortcode as the source of the wpvrelatedto attribute, nested in the other shortcode like this:

[wpv-view name="Your Venue View" wpvrelatedto="[wpv-view name='Your Exhibition View']"]

This technique is called passing arguments to Views and is described in more detail here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1234462

Hi Christian,
thank you for the description. I think I understood and it is working until the final step: The only relationship query I can see is "Select posts that are children of..." while I need to display the *parent* venues of which the exhibitions are the child(ren)?

The id list works: hidden link
but the map now has disappeared: hidden link

#1234477
Screen Shot 2019-04-23 at 10.27.39 AM.png

I hope this screenshot will help. Look for the Query Filter panel in the View editor screen. This is where you add arbitrary filters (not front-end filter controls). If you cannot see "Query Filter", scroll up to the top right corner of the screen and click "Screen Options". You can enable the Query Filter panel here. Then click "Add a filter" and choose "Post relationship or repeatable field groups owner". Then select the Venues / Exhibitions post relationship and choose the options as shown attached here, "The post with ID set by a shortcode attribute wpvrelatedto". This configures the filter to respond to the shortcode attribute "wpvrelatedto", where we you have placed your comma-separated list of exhibition post IDs.

#1234492
Bildschirmfoto 2019-04-23 um 16.48.56.png
Bildschirmfoto 2019-04-23 um 16.51.17.png
Bildschirmfoto 2019-04-23 um 16.53.50.png

Thank you,
I think I am at the same place, but it looks slightly different on my screen – not "any" relation but only "child of"…?

#1234549

May I log in to your wp-admin area to see what's going on? Please provide login credentials in the private reply fields here.

#1234721

Okay I see, your site hasn't migrated to the new relationship system. No problem, a few adjustments are needed. I modified the View of Exhibitions to produce a comma-separated list of the parent Venue IDs, not Exhibition IDs. I used the Loop
wizard to generate a "list with separators". Then in the View of Venues, I added a post ID filter instead of a post relationship filter. I combined the two shortcodes in the Page here: hidden link

Seems to be working as expected now, can you confirm?

#1234824
Bildschirmfoto 2019-04-24 um 08.09.41.png

Thank you, yes this look like the expected result now.

However, when you mentioned the word "migration"… As we intend to develop this site further in particular with functionalities based on relationships, the more sustainable solution will be to migrate to the new relationship system and to resolve it the way you suggested in your first reply.

To this end, I started the migration manager. Which detected LOT of legacy relationship code that might cause backward compatibility issues. Actually, there are many code segments found in content templates, forms, and post content, but it always refers to the same code snippet: We are referring to fields from related posts via id=[wpv-post-field name='_wpcf_belongs_venue_id'].
e.g. [wpv-post-field name='wpcf-venue_city' id=[wpv-post-field name='_wpcf_belongs_venue_id']] to display the City of the parent Venue on the Exhibition page.

Will this method/coding style work also with the new relationship system, or will we need to replace it by a different way of calling the field content from related posts?

Thank you for your support, highly appreciated!

#1235068

After migrating, the preferred syntax will be:

[wpv-post-field name='wpcf-venue_city' item='@relationship-slug.parent']

You can find the relationship slug in Toolset > Relationships after the migration.