Anon function and add_meta_box

I am building a WordPress management plugin (so far going really well) however I am having a slight issue below is what I am trying to acheive and the problem.

I am building a Meta manager and for the most part works.

I have created a custom post type called “meta_box” and created a dynamic field manager which works the problem I am having is after storing the meta box data in a post I am then running an anon function as follows:

‘meta_box’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1
);
$meta_boxes = get_posts($meta_box_query);

foreach($meta_boxes as $meta_box){
$meta_title = $meta_box->post_title;
$meta_id = preg_replace(‘-‘,’_’,$meta_box->post_name);
$meta_screens = get_post_meta($meta_box->ID,’screens’,true);
add_meta_box(
$meta_id,
$meta_title,
function(){
// meta fields render code
},
$meta_screens,
‘advanced’
);
}

});
?>

Now the above code loads the first meta box but doesn’t load anymore. is there something I am missing? I was thinking would I need to add the index into the foreach loop or is it something else?

Any assistence with this would be greatly appreciated.

Thanks

Read more here:: Anon function and add_meta_box

Leave a Reply

Your email address will not be published. Required fields are marked *