• Hi every body,

    When we are having problems because wordpress uses too much system resources, I have a way to reduce the query load:

    Join Post Meta: We will use often post_meta should work first of all we have to join this table.

    function kk_posts_join($join) {
        global $wpdb;
        $join .= " LEFT JOIN $wpdb->postmeta metapic ON ($wpdb->posts.ID = metapic.post_id AND metapic.meta_key = 'thumbs') LEFT JOIN $wpdb->posts pic ON (pic.ID = metapic.meta_value)";
        $join .= " LEFT JOIN $wpdb->postmeta metacon ON ($wpdb->posts.ID = metacon.post_id AND metacon.meta_key = 'icon')";
        $join .= " LEFT JOIN $wpdb->postmeta metaview ON ($wpdb->posts.ID = metaview.post_id AND metaview.meta_key = 'views')";
        return $join;
    }

    add_filter('posts_join', 'kk_posts_join');

    And get some field:

    function kk_posts_fields($fields) {
        $fields .= ',pic.guid AS thumbs,metacon.meta_value AS icon, metaview.meta_value AS view';
        return $fields;
    }

    add_filter('posts_fields', 'kk_posts_fields');

    Fields:
    Default wordpress wp_posts. * When retrieving the data, we will take the necessary fields.

    Somethink like there:

    function kk_posts_fields($fields) {
        global $wpdb
        $fields = "$wpdb->posts.post_title,$wpdb->posts.post_name,$wpdb->posts.post_content,$wpdb->posts.ID,$wpdb->posts.post_date,pic.guid AS thumbs,metacon.meta_value AS icon, metaview.meta_value AS view";
        return $fields;
    }

    We have reduced a lot of query of wordpress then, wish you success. Sorry for my English.

    [sig moderated as per the Forum Rules]

  • The topic ‘Optimize Query WordPress With Post Meta’ is closed to new replies.