WordPress.org

Ready to get started?Download WordPress

Forums

WPDB Query Slow on Multiple Taxonomy Search (1 post)

  1. rckmnx
    Member
    Posted 10 months ago #

    Hello, I am doing something wrong.

    I added a custom search function that searches for taxonomy_terms.
    It works like a charm when I have 2/3 queries, but when I add more I end up having a 100% cpu process on mysql, and the server goes down.

    So, here is what I did:

    public static function queryTours() {
    		global $wpdb;
    
    		$query['select']="SELECT posts.ID FROM {$wpdb->posts} AS posts ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS destinations ON posts.ID=destinations.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS types ON posts.ID=types.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS categories ON posts.ID=categories.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS capacity ON posts.ID=capacity.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS rooms ON posts.ID=rooms.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS classification ON posts.ID=classification.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->term_relationships} AS features ON posts.ID=features.object_id ";
    		$query['select'].="INNER JOIN {$wpdb->postmeta} AS prices ON (posts.ID=prices.post_id AND prices.meta_key = '_" ."price') ";
    		$query['where']="WHERE (posts.post_status = 'publish' OR posts.post_status = 'private') ";
    		$query['where'].="AND posts.post_type = 'tour' ";

    The website is currently in localhost, as I am still developing it.

    Does anyone have any tips I could do to improve it? I'm kinda lost on this for about a week :/

Reply

You must log in to post.

About this Topic