• Resolved thranduil

    (@thranduil)


    I have custom made search in my WordPress. I did not made the search my self but it uses this:

    
                        $args['post_type'] = array('post', 'page');
                        $args['post_status'] = 'publish';
                        $args['s'] = $search_string;
                        $args['orderby'] = 'date';
                        $args['order'] = 'DESC';
                        $args['suppress_filters'] = 0;
                        $args['paged'] = $paged;
                        $search_query = new WP_Query($args);
                        global $search_query;

    code to search. But this do not search for all site content and thats why I want to use Relevanssi, what seems to be ideal for what I need, but when I download and install the plugin then set it up by building the index, the search do not find anything. It just do not work. Some ideas whats wrong ?

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

    (@msaari)

    Instead of $search_query = new WP_Query($args);, do this:

    $search_query = new WP_Query();
    $search_query->parse_query( $args );
    relevanssi_do_query( $search_query );

    Now you should have Relevanssi-generated results in $search_query->posts.

    However, if you have this in your search results template, it’s not the right way to do this; a better way would be to remove all this and keep the default loop, and instead set the parameters like this:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_set_search_parameters' );
    function rlv_set_search_parameters(?$query ) {
        $query->set( 'orderby', array( 'date' => 'DESC' ) );
        $query->set( 'post_type', array( 'post', 'page' ) );
        return $query;
    }

    Having that in your theme functions.php will set the same parameters, and the default loop will provide the same results.

    Thread Starter thranduil

    (@thranduil)

    Thanks @msaari this:

    $search_query = new WP_Query();
    $search_query->parse_query( $args );
    relevanssi_do_query( $search_query );

    this fix the problem. But if I use orginal loop as you said, I just need to add code what you providet:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_set_search_parameters' );
    function rlv_set_search_parameters( $query ) {
        $query->set( 'orderby', array( 'date' => 'DESC' ) );
        $query->set( 'post_type', array( 'post', 'page' ) );
        return $query;
    }

    at functions.php and then use wordpress orginal search code in my search.php ?

    Plugin Author Mikko Saari

    (@msaari)

    Yes, that function will then modify the parameters for the default loop in search.php.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Do not work on custom made search.’ is closed to new replies.