Support Forums

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

Viewing 9 posts - 1 through 9 (of 9 total)
  • Rai Uriarte
    #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/IJvuPdr9fAk

    Thanks.

    Trevor Moderator
    #62009

    Great 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
    #62023

    Hi 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
    #62025

    Hi 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
    #62078

    Hi 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
    #62122

    Good 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
    #62225

    One 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
    #62230

    Hi, 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 folder

    If you want to make the results template specific to a form, use the numbered option.

    Rai Uriarte
    #69111

    Many thanks Trevor, I simplified the need and it works perfect.
    Thanks.

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Custom search results’ is closed to new replies.