• Resolved Андрій

    (@andxbes)


    Based on the plugin settings, the request should be via “OR”, but “AND” is set, and it searches not by a single word, but as a sentence

    in function get_acf_conditions

    Search example “Jack Pine”

    • This topic was modified 2 years, 7 months ago by Андрій.
    • This topic was modified 2 years, 7 months ago by Андрій.
    • This topic was modified 2 years, 7 months ago by Андрій.
    • This topic was modified 2 years, 7 months ago by Андрій.
    • This topic was modified 2 years, 7 months ago by Андрій.
    • This topic was modified 2 years, 7 months ago by Андрій.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Андрій

    (@andxbes)

    I would also like to add sorting by metafield, for example this code works correctly for me

    <?php 
    add_filter('posts_orderby', function ($orderby, $query) {
        if (!is_admin() && $query->is_main_query() && $query->is_search()  && class_exists('AcfBetterSearch\AcfBetterSearch')) {
            $s = esc_sql($query->get('s'));
            $orderby = "CASE WHEN a.meta_value LIKE '%{$s}%' THEN 1 ELSE 2 END, $orderby";
        }
        return $orderby;
    }, 10, 2);

    First it returns complete matches, and then by word.

    • This reply was modified 2 years, 7 months ago by Андрій.
    • This reply was modified 2 years, 7 months ago by Андрій.
    • This reply was modified 2 years, 7 months ago by Андрій.
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @andxbes,

    Thank you for your message.

    Search works by either searching for the entire sentence (in the order entered in the search field) or all words from the sentence entered in the search field. Standard search in WordPress works in a similar way – i.e. if you enter 3 words in the search field, all these words must be in a given post. They may be in a different order, but they must be there. We relied on the search engine in WordPress, which is why the functionality works the way it does.

    Best,
    Mateusz

    Thread Starter Андрій

    (@andxbes)

    In fact, the WP itself searches for both whole phrases and words, and makes relevant results, posts with whole phrases have the highest order, and posts with partially found words have a lower order WP_Query::parse_search_order()

    Thread Starter Андрій

    (@andxbes)

    After installing your plugin, I came across the fact that it doesn’t quite search using custom fields the way the WP itself does using standard fields. But with a little modification you can achieve an acceptable result. In any case, thanks for your work.

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

The topic ‘Found a mistake in the selection by custom fields’ is closed to new replies.