The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
Forums › Forums › Search & Filter Pro › Custom search results
- This topic has 8 replies, 2 voices, and was last updated 7 years, 10 months ago by Rai Uriarte.
-
Rai Uriarte(Private) October 4, 2016 at 4:00 pm #61938
Hi, I want something custom, any idea how to make it possible.
I need to search in 3 different custom post types
and show the result separatly and in different format for each of the custom post types.Here is a video:
https://youtu.be/IJvuPdr9fAkThanks.
Trevor Moderator(Private) October 4, 2016 at 7:44 pm #62009Great video.
You want a series of results, from multiple post types, which would normally come out all mixed up, to be sorted and probably have a sub-title as each type starts?
If you know what the custom post types are beforehand, and you use the shortcode method, which then gives you the use of the results.php file, the results come in an array. It must be possible to pre-sort that array before looping through it, and using local variables to detect when the post type changes (and insert the title at that point), and what it is for each post type, where you can use a php switch case structure to have different html output around the fields, and even different fields.
But that is a lot of coding. Probably 15-20 hours, and that will not be cheap, not that I or Ross have any free time anyway 🙁
Rai Uriarte(Private) October 4, 2016 at 8:08 pm #62023Hi Trevor,
What I was thinking was to conditionate the results.php depending on the template we will use and then print the results depending of the custom post types.
I have a developer so, if you help to track a way to do it, we can do it.
And I imagine if my idea is not makeable, the second option, to separate the page in differents tabs, each one with their one filters and results, right?.
Help me to see the way Trevor.
Trevor Moderator(Private) October 4, 2016 at 8:13 pm #62025Hi Rai
You didn’t say. Did you expect to have more than one type of post type in each set of results, or just one post type? Just one post type makes it much easier.
As it is late here now, it will be morning when I reply.
Rai Uriarte(Private) October 5, 2016 at 1:40 am #62078Hi Trevor,
The ideal scenario is this:
One search field for 4 different post types
The results shows separately the 4 different post types in a special order and with a special design each one.And if possible, each one has a “sort by” dropdown option.
The NOT so ideal scenario is:
One search field for 4 different post types
But the results separates in different tabs as is in here:https://www.yogatrail.com/s/newyork?type=event
See how the url pass the search query between the different tabs so the search in each custom post type?, can we do that in any way with S&F.
Please tell me what you think.
Thanks
Trevor Moderator(Private) October 5, 2016 at 10:40 am #62122Good morning Rai
To do the former option would be easier, in part.
S&F Pro already has the option to sort results by Post Type, so all you need to do is to format the results differently.
The standard results.php is structured like this:
<?php while ($query->have_posts()) { $query->the_post(); ?> OUTPUT THE POST HERE <?php } ?>
Instead you would do:
<?php while ($query->have_posts()) { $query->the_post(); switch (get_post_type( get_the_ID() )) { case 'Post Type A': ?> OUTPUT THE POST HERE if it is Post Type A <?php break; case 'Post Type B': ?> OUTPUT THE POST HERE if it is Post Type B <?php break; case 'Post Type C': ?> OUTPUT THE POST HERE if it is Post Type C <?php break; } } ?>
You would have a little bit more code if you needed to detect the start and end of the output of each post type (for example to start a background box or add a sub-title.
As to sort options, I do not know.
Rai Uriarte(Private) October 5, 2016 at 3:43 pm #62225One question, by changing the results.php you mean to change that file on the plugin or locally on the theme?. I ask because I want to know if this will affect all the Search Forms.
Thanks for your kindly help Trevor.
Trevor Moderator(Private) October 5, 2016 at 3:49 pm #62230Hi, there are, in effect, three potential results templates in Shortcode mode for EACH form:
Let us say the form has an ID of 6799.
1. The plugin first looks in the theme folder, search-filter sub-folder for a file called 6799.php
2. If it does not find that, THEN it uses the results.php file in that same folder
3. If it does not find that it uses the results.php file in the plugin templates folderIf you want to make the results template specific to a form, use the numbered option.
Rai Uriarte(Private) November 7, 2016 at 8:51 pm #69111Many thanks Trevor, I simplified the need and it works perfect.
Thanks. -
AuthorPosts
The topic ‘Custom search results’ is closed to new replies.