Combining multiple custom fields into single query?
-
I have a series of 3 custom fields that I am calling for each post. On pages where I have 10+ posts displaying, it is adding a lot of extra database queries. I’m hoping there is some way to combine the 3 queries into a single one, to hopefully reduce the load on the server. Here is what I have now, within the post loop so the 3 fields show conditionally on each post (must be conditional because the span shouldn’t display at all if the field is empty):
<?php $cat1 = get_post_meta($post->ID, 'level', true); if ( $cat1 ) { echo '<span class="cat1">'; echo $cat1; echo '</span>'; } ?> <?php $cat2 = get_post_meta($post->ID, 'time', true); if ( $cat2 ) { echo '<span class="cat2">'; echo $cat2; echo '</span>'; } ?> <?php $cat3 = get_post_meta($post->ID, 'cat', true); if ( $cat3 ) { echo '<span class="cat3">'; echo $cat3; echo '</span>'; } ?>
Any ideas for how to make this more efficient?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Combining multiple custom fields into single query?’ is closed to new replies.