Skip Navigation

[Résolu] Custom Search question

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to display information from grandparent, parent, and child posts.

Solution:
Use the $slug syntax to retrieve information from parent fields, and use Content Templates to change the context and display grandparent information.

Relevant Documentation:
https://toolset.com/documentation/user-guides/front-page-filters/
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

This support ticket is created Il y a 6 années et 11 mois. 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
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 12 réponses, has 2 voix.

Last updated by Craig Il y a 6 années et 11 mois.

Assisted by: Christian Cox.

Auteur
Publications
#530496

I am considering using Types & Views to create a Custom Search, but wondered if what I am going to try and achieve will be possible…?

A visitor visits the page and selects a 'city' from a select menu, the relevant 'suburbs' of the selected city would populate a second select menu, once the suburb is selected, the relevant information for that suburb would be displayed.

Does this sound possible with Types & Views? If so, what would be the best way to set up the CPT to allow me to target the suburbs from the cities?

Cheers,
Craig

#530604

Hi Craig, thanks for considering Toolset! We actually have a reference site set up with a very similar workflow, and I would like to invite you to check it out over in our demo area:
http://discover-wp.com/site-types/bootstrap-estate-layouts/

You can create an account and install a test copy of this site on our server to play around with. The main home search form is created using Types and Views, and you'll see that the options for "City" update automatically when a "State" is selected. Cities and States are both Custom Post Types, and each Home must be associated with both a City and State in its post editing screen.

Let me know if you would like any additional information about this and I'll be glad to help.

#530954
Capto 2017-05-31_02-39-22_pm.png

Hi Christian,

Thanks for that pointer. I have tried setting up something similar at hidden link

The select menus are working and they update some of the information in the paragraphs below, but there are a couple of issues I cannot seem to get working…

1. The text below the Select menus is visible even before making a choice from the menus. Is there a way to show some default text prior to making a selection? Something like "please select your town and development to display the relevant parking information".

2. I would like to populate the *Development*, *Town* and *Officer* information (highlighted in bold) automatically based on the selections made. I think I have added the parent and child information correctly, but don't see any way to insert the fields into the Content Template which would enable these to be populated automatically. Is this possible?

Kind regards,
Craig

#531015

1. Is there a way to show some default text prior to making a selection?
There's not an option like this for a View's default text, so the easiest way to accomplish it is to split up your search form and search results. On this page, include just the search form along with any default text, and require the user to press a submit button. This would redirect them to another page (which is really just a clone of this page) with the entire search form and search results included.

2. I...don't see any way to insert the fields into the Content Template which would enable these to be populated automatically. Is this possible?
You should add these filters to your View's Filter Controls area, so that they are populated automatically. See section 2.2 here:
https://toolset.com/documentation/user-guides/front-page-filters/

#531061
Capto 2017-05-31_05-32-53_pm.png
Capto 2017-05-31_05-25-45_pm.png

Hi Christian,

Thanks again for the pointers – I now have it working - to a fashion. I will tidy things up and get it looking better soon.

I still have a problem with populating the information returned from the search into the results…

I have attached a screen grab of the "Developments CPT" with the relations displayed. I would like to be able to insert these into the search results automatically, but can't see any shortcodes anywhere to add these in.

If I add them like you suggested in the "Adding inputs to the search form" section, I get more fields to choose from in the Search Form, but I don't need any further options there, I just want the Development Name, Town and Officer to be displayed as per the bold text in the "Car Parking Search Results" screen grab i fthis is possible.

#531448

Okay so I assume we're talking about a View of Car Parks, correct? And Car Parks are children of Developments, which are children of Towns? If so:

Chiefswood Road - this is the post title of the parent Development, so you can use [wpv-post-title id="$development"] in the View of Car Parks, assuming the Development post type's slug is "development". Take a look at the documentation here that covers displaying fields of parent posts: https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

Melrose - this is the post title of the parent Town, so you can use [wpv-post-title id="$town"], assuming that the Town post type's slug is "town". Check the link I posted above for more info on this shortcode.

Susan Turner Need more information about this. What is shown here if there is more than one Car Park in a Development, and those Car Parks have different Officers? What is the slug of the custom field used to store this information?

#531527

Hi Christian,

Thanks for the info about fields from parent posts, I will give that a try and let you know how it goes.

Regarding Officers, they are a separate Post Type with a slug of "officer". I currently have the "Car Park detail" Post Type set as a child of "officer".

A Town can have many Developments, but only one Officer.

Each Development will only have one Car Park.

I hope that makes sense.

#531538

Hi Christian,

I recorded a short screencast showing the results of adding in the shortcodes to display the development (which worked), town (which didn't work) and officer (which worked)

hidden link

At the end of the screencast you can see the code used to display the results.

#531596

Oh okay, I see the code at the end of the video. Is it possible for me to take a look in the wp-admin area? I'd like to check a couple of configurations. If that's okay, please provide login credentials for me here in the private reply fields. I won't make any changes, just review settings.

#531630

Ok got it, I was overlooking the grandparent relationship issue. Here's a document that describes how you can use one more Content Template to wrap the shortcode I mentioned earlier:
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

[wpv-post-title id="$town"]

This won't work in the context of the Car Park, so you must use a Content Template to set a new context at the Development level. Use a Content Template to display the parent (development) information, and inside this Content Template, use the ‘id’ arguments to access its own parent (town), which is the grandparent of Car Park. Let me know if I can be of further assistance here.

#531742

Hi Christian,

Thank you so much for this info. Makes sense now that I read it. I will give this a try early next week and let you know how I get on.

I am out of the office now until Tuesday morning (BST).

I really appreciate the pointers you have provided, awesome support.

Kind regards,
Craig

#532461

Okay, I'll be out of the office for a few days beginning Thursday so another supporter will cover my queue. Feel free to reach out if you have questions. Thanks!

#533860

Hi Christian,

I just wanted to let you know that your help and pointers have got e to the point where all is working perfectly – thank you 🙂

Kind regards,
Craig

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.