Sage: Unwanted "I Feel Lucky"-like search functionality

Created on 29 Nov 2017  路  1Comment  路  Source: roots/sage

Submit a feature request or bug report


What is the current behavior?

Mixed behavior: For some results it ignores search.blade.php and loads the first post (I am also utilizing custom post types, in addition to the standard post types). For other results, it lists results on a page as expected.

What is the expected or desired behavior?

Load search.blade.php and display a list of results.


Bug report

Please provide steps to reproduce, including full log output:

  • Go to https://online.usm.edu
  • Click Search icon (magnifying glass)
  • For search results page: Search for "test"
  • For redirection: Search for "nursing"

Please describe your local environment:

Sage version: 9.0.0-beta.4

WordPress version: 4.9

OS: macOS High Sierra 10.13.2 Beta

PHP: 7.1.1

NPM/Node version: 5.5.1/6.10.2

Where did the bug happen? Development or remote servers?

Both development and remote servers

Is there a related Discourse thread or were any utilized (please link them)?

No

Most helpful comment

Resolved. Issue was on my end. When adding a custom post type I had added a filter on template_include, which would use a single custom template for a group of types. Since these custom post types are queried on search, I had forgot to add !is_search() on the boolean check for post types:

/**
 * Handle template inclusion of single program so we use the right file.
 */
add_filter('template_include', function ($template) {
    $types = ['undergrad_pt', 'grad_pt', 'cert_pt', 'hybrid_pt', 'exec_pt'];
    $post_type = get_post_type();

    if (in_array($post_type, $types) && !is_search()) {
        return locate_template(['single-program.blade.php']);
    }

    return $template;
});

>All comments

Resolved. Issue was on my end. When adding a custom post type I had added a filter on template_include, which would use a single custom template for a group of types. Since these custom post types are queried on search, I had forgot to add !is_search() on the boolean check for post types:

/**
 * Handle template inclusion of single program so we use the right file.
 */
add_filter('template_include', function ($template) {
    $types = ['undergrad_pt', 'grad_pt', 'cert_pt', 'hybrid_pt', 'exec_pt'];
    $post_type = get_post_type();

    if (in_array($post_type, $types) && !is_search()) {
        return locate_template(['single-program.blade.php']);
    }

    return $template;
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlariza picture jlariza  路  5Comments

mquellhorst picture mquellhorst  路  3Comments

williamscotholmes picture williamscotholmes  路  4Comments

oxyc picture oxyc  路  4Comments

evertsemeijn picture evertsemeijn  路  3Comments