How can I reduce the number of database query calls for this custom homepage?

You could just write your own query, too. That way, it’s one query per category:

global $wpdb;

$query = '
SELECT wpp1.*
FROM ' . $wpdb->posts . ' AS wpp1
LEFT JOIN ' . $wpdb->term_relationships . ' AS wptr1 ON wptr1.object_id = wpp1.ID
WHERE post_type = %s
AND post_status = %s
AND wptr1.term_taxonomy_id = %d
ORDER BY wpp1.post_date DESC
LIMIT %d
';

$query = $wpdb->prepare(
    $query,
    // Args: post type, post status, term taxonomy ID, number of posts
    'post', 'publish', 80, 3
);

$posts = $wpdb->get_results(
    $query,
    ARRAY_A
);

Leave a Comment