• Resolved nsp-code

    (@nsp-code)


    Hi,
    I’am the developer of Post Types Order plugin. Some users reported an issue when using the following plugins along with Relevanssi:

    • Relevanssi – A Better Search
    • Theme my Login
    • Post Types Order

    Practically in this conjunction, the search result page does not return any data
    https://www.ads-software.com/support/topic/conflict-with-relevanssi-search-plugin-because-of-wp-query-loop/

    I checked into this code and find an issue in plugin code (Relevanssi – A Better Search), can you check the following fix? Practically it should relay on current query and not global $wp_query, since those can be different and the Relevanssi alter queries which should left untouched, they are not even search :

    /lib/init.php

    add_filter('the_posts', 'relevanssi_query');
    change to
    add_filter('the_posts', 'relevanssi_query', 99, 2);

    /lib/search.php
    update the function relevanssi_query to:

    function relevanssi_query($posts, $query = false) {
    	$admin_search = get_option('relevanssi_admin_search');
    	($admin_search == 'on') ? $admin_search = true : $admin_search = false;
    
    	global $relevanssi_active;
    	//global $wp_query;
    
    	if (!$query) return $posts;
        
        if( ! $query->is_search() )
            return $posts;
    
    	$search_ok = true; 							// we will search!
    	if (!is_search()) {
    		$search_ok = false;						// no, we can't
    	}
    
    	// Uses $wp_query->is_admin instead of is_admin() to help with Ajax queries that
    	// use 'admin_ajax' hook (which sets is_admin() to true whether it's an admin search
    	// or not.
    	if (is_search() && $query->is_admin) {
    		$search_ok = false; 					// but if this is an admin search, reconsider
    		if ($admin_search) $search_ok = true; 	// yes, we can search!
    	}
    
    	if ($query->is_admin && empty($query->query_vars['s'])) {
    		$search_ok = false;
    	}
    
    	// Required so that the admin dashboard page search works.
    	if ($query->is_admin && $query->query_vars['post_type'] == 'page') {
    		$search_ok = false;
    	}
    
    	// Disable search in media library search
    	if ($search_ok) {
    		if ($query->query_vars['post_type'] == 'attachment' && $query->query_vars['post_status'] == 'inherit,private') {
    			$search_ok = false;
    		}
    	}
    
    	$search_ok = apply_filters('relevanssi_search_ok', $search_ok);
    
    	if ($relevanssi_active) {
    		$search_ok = false;						// Relevanssi is already in action
    	}
    
    	if ($search_ok) {
    		$query = apply_filters('relevanssi_modify_wp_query', $query);
    		$posts = relevanssi_do_query($query);
    	}
    
    	return $posts;
    }

    The above works fine in my test environment, might require more testing.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nsp-code

    (@nsp-code)

    Also if the code need to apply only on the main query, it might be a good idea to compare the $wp_query hash with the passed through $query hash and continue only if match.

    Plugin Author Mikko Saari

    (@msaari)

    Thanks! Based on some quick testing this seems to work and if it removes compatibility issues then that’s a huge bonus.

    I’ll have to do some more testing, but so far this seems good.

    Thank you nsp-code and Mikko Sari for coming together to resolve it. It shows the spirit of WordPress community.

    Thanks,

    Saurabh

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conflict with Relevanssi in conjunction with Theme My Login and Post Types Order’ is closed to new replies.