• Hello,

    It looks like the Relevanssi “Use search for admin” doesn’t apply for the FInd Posts modal.
    I’m using Custom Meta Boxes 2 (CMB2)alongside CMB2 Post Search Fieldto link a post to another post. The CMB2-Post-Search-Field extension uses the native WP Find Posts Modal, which triggers the get_postsmethod in: website/wp-admin/includes/ajax-actions.php:1781 via an AJAX call with action=find_posts.

    I would expect the “Use search for admin” to apply for all native WP searches, but this one as left out for some reason.

    Is there any way to integrate Relevanssi with the Find Posts modal?

    Thank you!

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

    (@msaari)

    If you can figure out a way to do that, I’m all ears. I don’t have a clue on how get on to that search.

    Currently Relevanssi uses the_posts filter hook to replace the WP default search.

    Thread Starter mclaurent

    (@mclaurent)

    I can give it a shot. Is it something that is on the road map for Relevanssi?

    Plugin Author Mikko Saari

    (@msaari)

    No, it hasn’t been so far, but if you can fix it, I’ll add it to the plugin.

    Thread Starter mclaurent

    (@mclaurent)

    It’s definitely quiet tricky to implement and I don’t think it’ll be feasible. The problem is that the AJAX find_posts does not set suppress_filtersto false, allowing relevanssi to use the get_posts filter to trigger the search. I have managed to overwrite the query parameters, so that suppress_filters=false, which returns the results nicely, but forces WordPress to trigger get_posts a second time somewhere else.
    This is the code I have used for my debugging:

    
    add_action('pre_get_posts', 'setAjaxSearchesAsSearches');
    function setAjaxSearchesAsSearches(&$query)
    {
        global $wp_query;
        $isCmb2Ajax = isset($_POST['cmb2_post_search']) && $_POST['cmb2_post_search'] && strcasecmp($_POST['action'], 'find_posts') === 0;
        if (is_admin() && $isCmb2Ajax && $query && $query instanceof \WP_Query && $wp_query && $wp_query instanceof \WP_Query) {
            $query->query_vars['suppress_filters']=false;
            $query->query['suppress_filters']=false;
            $query->is_search = true;
            $wp_query->is_search = true;
            $wp_query->is_admin = true;
            $wp_query->query_vars['s'] = $_POST['ps'];
    
        }
        return $query;
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Relevanssi not integrating with the WP Find posts modal’ is closed to new replies.