• I am learning Plugin Development. I have three MetaBox in a Class. I have to use $stored_meta = get_post_meta($post->ID); in each MetaBox call back function. How can I use it globally ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • What do you mean globally?

    Moderator bcworkz

    (@bcworkz)

    I’m assuming you wish to avoid redundant queries on a page using multiple boxes.

    If you declare a var global, it’ll be available from any callback. You could instead use the WP_Object_Cache to temporarily save and get data.

    The order in which meta box callbacks are called can be ambiguous. Each one should first try to utilize existing global or cached data. If it it does not yet exist, then do get_post_meta() and save the result for future use.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Usage of call back function of add_meta_box()’ is closed to new replies.