• Resolved Zwaar Contrast

    (@zwaar-contrast)


    Hey there,

    I’m trying to create a live search, but Relevanssi seems to ignore my post_status parameter which I set to publish. I need to do this because AJAX requests are performed within the admin scope, and because of that “Drafts” are also returned. I don’t want this of course.

    On a regular search with the same search string, Relevanssi does not return the draft. Also, when I perform the AJAX request using regular $wp_query->get_posts(), I also don’t get the drafts.

    My code is as follows:

    add_action('wp_ajax_nopriv_obeymag_search', 'obeymag_search'); // for not logged in users
    	add_action('wp_ajax_obeymag_search', 'obeymag_search');
    
    	function obeymag_search()
    	{
    		global $wp_query;
    		global $post;
    
    		$search = $_POST['search_val'];
    
    		$args = array(
    			'post_status'=>'publish',
    			'post_type' => 'post',
    			'suppress_filters' => true,
    			's'=>$search,
    			'no_found_rows'=>true,
    		);
    		$wp_query = new WP_Query($args);
    		$wp_query->parse_query( http_build_query( $_GET ) );
    		$wp_query->set( 'cache_results', false );
    
    		if ( function_exists( 'relevanssi_do_query' ) ) {
    			relevanssi_query( $wp_query );
    		}else{
    			$wp_query->get_posts();
    		}
    
    		die((string)print_r($wp_query));
    
    		if ( $wp_query->have_posts() ) : 
    
    			while ( $wp_query->have_posts() ) : $wp_query->the_post();
    				Starkers_Utilities::get_template_parts( array( 'parts/shared/article-link' ) );
    			endwhile;
    
    			wp_reset_postdata();
    
    		else:
    			echo '';
    		endif;
    		die();
    	}

    https://www.ads-software.com/plugins/relevanssi/

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

    (@msaari)

    Yes, Relevanssi ignores post_status. I just released version 3.3.3, which includes support for post_status.

Viewing 1 replies (of 1 total)
  • The topic ‘Post Status when using AJAX’ is closed to new replies.