0

I need to send my metabox information to a function - the meta is already called on page template

$meta = get_post_meta(get_the_ID())

but I need to use this data in function

the metaboxes are around 20 and containing different information (strings, arrays, multidimensional arrays, etc)

For best WordPress performance which is better option - to send all the meta to function (case 1) or to send just the ID of the post and inside the function to call the meta again (Case 2), or it is equals?

Case 1

somefunction($meta);

Case 2

//page.php
somefunction(get_theID()); 

//functions.php
somefunction($id){
    $meta = get_post_meta($id);
    //rest of the code handling the meta
}
1

Meta retrieval go through Cache API, so retrieving same data for same post during same page load won't cause database re–querying (and in case of Object Cache even between different page loads).

So that concern aside I would recommend (as usual) to:

  1. Architect in a way that makes sense, not in a way that might or might not be faster (guessing isn't worth it)
  2. Benchmark the result
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.