• Resolved remidk

    (@remidk)


    Hello,

    I try to make a custom search.php but when I run the search, no results are displayed. WordPress tells me that results are founded but my request found_posts is always 0. My project uses Divi theme but I tried with OceanWp and Astra too.

    I tried solutions found here : https://www.relevanssi.com/knowledge-base/debugging-relevanssi-searching-issues/. Parameters and MySQL request look fine. When I look at results, I can see it’s not empty : array(size=3) 51 => float 10.75 130 => float 10.75 132 => float 10.75

    I feel like there is something missing to let the theme use Relevanssi. Is there anything I can do to let Relevanssi display the results?

    Thanks for your Help ??

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

    (@msaari)

    Can you show me your custom template? Are you using the global $wp_query or running a custom query? If you run a custom query, ensure you set the relevanssi query parameter to true.

    Thread Starter remidk

    (@remidk)

    I’m using a new WP_query. Here the code :

    $query_args = array(
    'post_type' => array('recette'),
    's' => $s,
    'posts_per_page' => 15,
    'relevanssi' => true
    );
    $query = new WP_query( $query_args );

    And for testing :

    if ( $query->have_posts() ) {
    echo $query->found_posts;
    while ( $query->have_posts() ) {
    $query->the_post();
    ?>
    <h2>Display test</h2>
    <?php
    }
    wp_reset_query();
    }

    I also tried with relevanssi_do_query( $query );

    Plugin Author Mikko Saari

    (@msaari)

    Looks good to me. Does the same search return results if you do it with the Relevanssi admin search (Dashboard > Admin search)?

    Thread Starter remidk

    (@remidk)

    I tried and it works well

    Plugin Author Mikko Saari

    (@msaari)

    The code you have should work. Is $query->posts empty? What about the results array from relevanssi_hits_filter? Or relevanssi_hits_to_show? Figuring out where the results go missing can help solve the problem.

    Thread Starter remidk

    (@remidk)

    $query->posts is always empty. If I try to print in relevanssi_hits_filter, I have this :

    Array ( [0] => WP_Post Object ( [ID] => 187 [post_author] => 1 [post_date] => 2024-08-22 09:45:13 [post_date_gmt] => 2024-08-22 07:45:13 [post_content] => [post_title] => fromage [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => fromage [to_ping] => [pinged] => [post_modified] => 2024-08-22 09:45:14 [post_modified_gmt] => 2024-08-22 07:45:14 [post_content_filtered] => [post_parent] => 0 [guid] => https://localhost/wordpress/wordpress/?post_type=recettes&p=187 [menu_order] => 0 [post_type] => recettes [post_mime_type] => [comment_count] => 0 [filter] => raw [relevance_score] => 5 ) [1] => WP_Post Object ( [ID] => 130 [post_author] => 1 [post_date] => 2024-08-02 14:26:06 [post_date_gmt] => 2024-08-02 12:26:06 [post_content] => [post_title] => [test] fromage vegan [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => test-fromage-vegan [to_ping] => [pinged] => [post_modified] => 2024-08-02 14:26:06 [post_modified_gmt] => 2024-08-02 12:26:06 [post_content_filtered] => [post_parent] => 0 [guid] => https://localhost/wordpress/wordpress/?post_type=recettes&p=130 [menu_order] => 0 [post_type] => recettes [post_mime_type] => [comment_count] => 0 [filter] => raw [relevance_score] => 5 ) [2] => WP_Post Object ( [ID] => 51 [post_author] => 1 [post_date] => 2024-07-29 17:56:33 [post_date_gmt] => 2024-07-29 15:56:33 [post_content] => [recette_infos][recette_details][searchform post_types="recettes"] [post_title] => test [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => test [to_ping] => [pinged] => [post_modified] => 2024-08-22 17:12:57 [post_modified_gmt] => 2024-08-22 15:12:57 [post_content_filtered] => [post_parent] => 0 [guid] => https://localhost/wordpress/wordpress/?post_type=recettes&p=51 [menu_order] => 0 [post_type] => recettes [post_mime_type] => [comment_count] => 0 [filter] => raw [relevance_score] => 2 ) ) Array ( )

    I didn’t find relevanssi_hits_to_show in the documentation. Do you have a link to this one ?

    Plugin Author Mikko Saari

    (@msaari)

    Oh, there’s a gap in the documentation. It’s basically the same as relevanssi_hits_filter, but the filtered array only has the posts that are displayed on the one page of results, when relevanssi_hits_filter has all the results found. It’s the last filter Relevanssi uses, so if you have results there, the problem is not Relevanssi.

    Thread Starter remidk

    (@remidk)

    I tried something like that :

    add_filter( 'relevanssi_hits_to_show', 'rlv_hits_filter' );
    function rlv_hits_filter( array $hits ) : array {
    $kept_posts = array();
    foreach ( $hits[0] as $_post ) {

    $kept_posts[] = $_post;
    }
    print_r($kept_posts);
    $hits[0] = $kept_posts;
    return $hits;
    }

    And it looks like we have some results :

    5112024-07-29 17:56:332024-07-29 15:56:33[recette_infos][recette_details][searchform post_types="recettes"]testpublishclosedclosedtest2024-08-22 17:12:572024-08-22 15:12:570https://localhost/wordpress/wordpress/?post_type=recettes&p=510recettes0raw6Array ( [0] => 51 [1] => 1 [2] => 2024-07-29 17:56:33 [3] => 2024-07-29 15:56:33 [4] => [recette_infos][recette_details][searchform post_types="recettes"] [5] => test [6] => [7] => publish [8] => closed [9] => closed [10] => [11] => test [12] => [13] => [14] => 2024-08-22 17:12:57 [15] => 2024-08-22 15:12:57 [16] => [17] => 0 [18] => https://localhost/wordpress/wordpress/?post_type=recettes&p=51 [19] => 0 [20] => recettes [21] => [22] => 0 [23] => raw [24] => 6 )

    I will try to check my child theme. Thanks for your help ! ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.