• Resolved aosmichenko

    (@aosmichenko)


    Hello,

    Thanks for this awesome plugin and its maintenance! I have a quick question, for some reasons search results are not showing posts that have exact title match.

    I am building query based on params in the URL like this:

    $builder_args = array(
    	        'post_type'      => 'builder',
    	        'posts_per_page' => 12,
    	        'paged'          => get_query_var( 'paged', 1 ),
                'order'          => 'desc',
                'orderby'        => 'menu_order date'
            );
            if($_GET['keywords']) {
                $builder_args['s'] = $_GET['keywords'];
            }
            if($_GET['builder-category'] || $_GET['builder-type']) {
                if($_GET['builder-category'] && $_GET['builder-type']) {
                    $builder_args['tax_query']['relation'] = 'and';
                }
                if($_GET['builder-category']) {
                    $builder_args['tax_query'][] = [
                        'taxonomy' => 'builder-category',
                        'field'    => 'slug',
                        'terms'    => [$_GET['builder-category']]
                    ];
                }
                if($_GET['builder-type']) {
                    $builder_args['tax_query'][] = [
                        'taxonomy' => 'builder-type',
                        'field'    => 'slug',
                        'terms'    => [$_GET['builder-type']]
                    ];
                }
            }
        $builder = new WP_Query($builder_args);

    If you can advise or need any debug information, I will be happy to provide it.

    Best regards,
    Alex

    The page I need help with: [log in to see the link]

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

    (@msaari)

    Looks like Relevanssi works; if I search for “classic constructions” on your site using the basic search, I get a bunch of results, with the exact match first. So, the problem is not in how Relevanssi works, but how this query is structured.

    Does it help if you add:

    $builder_args['relevanssi'] = true;

    inside the if($_GET['keywords']) conditional?

    (Relevanssi doesn’t understand 'orderby' => 'menu_order date', you need to change that to 'orderby' => array( 'menu_order' => 'desc', 'date' => 'desc' ).)

    Thread Starter aosmichenko

    (@aosmichenko)

    Thank you very much! Issue is solved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom post type search’ is closed to new replies.