[wp-hackers] multiple calls to get_post_meta back to back as opposed to one call
halukkaramete at gmail.com
Thu Feb 7 21:55:21 UTC 2013
Very interesting. I would have never guessed that that would be the
On Thu, Feb 7, 2013 at 1:43 PM, Andrew Nacin <wp at andrewnacin.com> wrote:
> On Thu, Feb 7, 2013 at 4:30 PM, Haluk Karamete <halukkaramete at gmail.com>wrote:
>> This question can be formulated as
>> Would it make sense ( from the mysql quiery point of view ) to build a
>> functionality so that the following 2 liner code
>> $fields = array('field_1','field_2',....'field_10');
>> will practically be speaking equal to something like
>> $field_1 = get_post_meta($post->ID,'field_1',true);
>> $field_2 = get_post_meta($post->ID,'field_2',true);
>> $field_10 = get_post_meta($post->ID,'field_10',true);
>> First approach will be done with a single but slightly more
>> complicated query whereas the latter will force 10 sql queries they
>> tend to be simpler.
> Test this and you will find that the latter is just one query, total. When
> you call get_post_meta(), all meta for that post is queried and cached.
> Additionally, only the first argument to get_post_meta() is required. Call
> it with just a post ID and you'll get back all metadata.
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers