Skip Navigation

[Resolved] Table display view relationship

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Author
Posts
#1238532

Hi

I'm trying to setup a table into table view which are set up in a "one-to-many" relationship, where a county can have several cities.

I have managed to set it up (hidden link ) and when I enter the name of a city into the search field it is found. hidden link.

Now I could also search for the county name and this would be achievable if I entered the name of the county into the city's post content ( hidden link - hidden link )

The idea is that I want the table structure to look exactly as in this screenshot ( hidden link ) where I have a header row with the county name and beneath the corresponding cities.

Here's the page for it :: hidden link

I can give you access to the admin area if you'd like

Can this be achieved?

Sincerely

#1238578

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - if you have one to many relationship setup, you can display the such output using nexsted view. Where you need one view to query your parent post type and one view to query your child post type.

If you can share the access details and for what relationship you want to display such results, I would be happy to configure it for you. Please create a test page and two views as said above and share access details.

#1238613

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I would like to know here do you need a search function as well with your view?

As - if you use nested view as I said where you need one view to query your parent post type (county) and one view to query your child post type (city).

If we use nested view the search function should not be used as the child view that queries (city) will be added to parent view's loop editor.

If you need search function, then nested view will not work here.

Then you need to use the following way to group by your results. You need to replace the field with your field.
https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

Please let me know which option you would like to implement so that I can guide you accordingly.

#1238620

I would like to be able to search for both a city and a county in the search box - hidden link

I'm not sure which method I'd prefer - but the end result I'd like to look like this hidden link and to be able to search for both a county and a city.

Do both methods accomplish the same result, meaning:
1. has this layout - hidden link
2. I'm able to search for both a county and a city?

#1238626

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've created the following view that queries parent (county):
=> hidden link

I've created another view that queries child (city)
hidden link

I've added those to view this page:
hidden link

The output on the frontend is as you can see: hidden link

This is the only possibility I can see now.

#1238748

Great

One more thing: would it be possible to hide those counties which are empty when doing a search ( hidden link ) via a parametric search conditional or something?

Regards

#1238976

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've pass the county post title as view's shortcode attribute:
=> hidden link

[wpv-view name="city-belongs-county" county="[wpv-post-title]" view_display="layout"]

And we are catching the shortcode attribute "county" within the view "city-belongs-county" as given under that is placed just after the shortocde [wpv-items-found]:
=> hidden link

 <h2> [wpv-attribute name="county"]</h2>

More info:
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/#accessing-the-arguments

I see now view is displaying expected results.
=> hidden link

#1238991

Awesome

I noticed you removed the "[wpv-no-items-found]" from the loop editor which is good because there're no multiple 'no item found' messages when searching for a city.

In case however that someone enters a city which doesn't exit at all, would it be possible to have a message displayed? ( hidden link )

Regards

#1239026

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As view is nested you need to manage using some jQuery/javascript.

Please check:
hidden link

I've added the following code to your child view (city) jS box:

jQuery(document).ready(function($){

  if($(".wpv-loop").find("tr").length == 0){
    $(".noitems").eq(0).show();
  }
  
});

As well as added the following HTML:

<div class="noitems" style="display:none;">
  No Items Found
</div>  

I hope this issue is fully resolved now, Please feel free to open a new ticket with your every new question you may have 🙂

#1239084

My issue is resolved now. Thank you!

#1244402

Thank You