Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mikko Saari

    (@msaari)

    The indexing setting is all you need. There’s no need to restrict the search to the post type if it’s the only one in the index. You only need the post_type parameter in the search query if you have multiple post types in the index and only want results from one post type.

    No filter functions are necessary.

    Thread Starter bluedogranch

    (@bluedogranch)

    Thanks! For some reason, I’m still getting results ranked by date, newest to oldest, with no post_type parameter. Where would I start to look for the problem?

    Plugin Author Mikko Saari

    (@msaari)

    What if you add &orderby=relevance&order=desc to the search query URL? Does that fix the problem? Are the results otherwise correct?

    Thread Starter bluedogranch

    (@bluedogranch)

    No, still by date. Maybe this is a problem with the search results template?

    Plugin Author Mikko Saari

    (@msaari)

    It’s possible, or something that overrides the sorting later. Are the results otherwise from Relevanssi? I.e. the correct post type and so on? If the results come from Relevanssi, you can try this snippet in your theme functions.php to override the order:

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    $query->set( 'orderby', array( 'relevanssi' => 'desc' ) );
    return $query;
    } );

    If this does not work, then yeah, let’s look at what your search results template has.

    Thread Starter bluedogranch

    (@bluedogranch)

    Ah, hah; that worked. Thanks!

    Now I will look in the search results template and see what might be overriding the results so I don’t need that filter.

    Plugin Author Mikko Saari

    (@msaari)

    It might be in the theme functions.php, or come from another plugin.

    Thread Starter bluedogranch

    (@bluedogranch)

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Restrict to one Custom Post Type’ is closed to new replies.