Leave a Reply

2 comments

  1. I’d like to see what the actual generated SQL is that WP_Query is using, but for now.

    ( You can use http://wordpress.org/extend/plugins/debug-bar/ to easily view the SQL query )

    Queries ordered by ‘random’ are inefficient. If you don’t need that remove it. If you do need a random order, consider removing it anyway and using PHP’s shuffle to randomize.

    LIKE queries are also fairly inefficient. Use = if you can.

    You might be faster to write a query of your own that pulls the post IDs out of the postmeta table and then use WP_Query with a simple post__in parameter to pull post content. This may or may not help, but is worth the experiment.

  2. You might be able to to take a load off the server by using a meta query using IN:

    $the_query = new WP_Query(array(
            'post_type' => 'listing',
            'post_status' => 'publish', 
            'category_name' => 'private_rental',
            'orderby' => 'rand',
            'meta_query' => array(
                        'key' => 'amenities',
                        'value' => $amenities,
                        'compare' => 'IN'
                        );
        ));
    

    The query you were trying to do looks like it was complicated, which may have caused excessive server load. IN will basically look for all the posts that have meta data of the key amenities that has a value within the fields the user is looking for. Definitely a more efficient query, imho