I am using AJAX to load my search results on my site, but would like to extend the search to include multiple keywords. However, I cannot do so with a WP_Query (as far as I know).

This is the code I have currently in my search function:

function load_search_results() {
    $query = $_POST['query'];

    $i = 1;
    $args = array(
        'post_type' => 'days',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'order' => 'DESC',
        's' => $query
    $search = new WP_Query( $args );


    if ( $search->have_posts() ) : 


            while ( $search->have_posts() ) : $search->the_post();$count = $search->post_count;

    else :

    $content = ob_get_clean();

    echo $content;


I have tried adding the keywords as an array, but that doesn’t work. The normal search function parses the URL to get the keywords, but because of the AJAX loading I don’t think thats an option. I suspect I will have to use something other than WP_Query, but I am not sure what.

Any ideas?

Read more here: Allow multiple keyword search on WordPress, whilst using AJAX to return search results


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: