Support Forum
Hi,
Is there any way to get all field values into a public array and filter with page id in front end
Ex:
$meta_boxes = apply_filters( 'rwmb_meta_boxes', array() );
Dump of Extended $meta_boxes_fields
object(stdClass)[600]
public 'head_home' => string 'Home'
public 'description_home' => string '<p> About Content</p>'
public 'head_about' => string 'Home'
public 'description_about' => string '<p> About Content</p>'
public 'gallery' =>
array
0 => string '56' (length=2)
1 => string '44' (length=2)
2 => string '42' (length=2)
3 => string '18' (length=2)
I want to Extended the $meta_boxes array like this or another way.
Dump of Extended $meta_boxes_fields in home
object(stdClass)[600]
public 'head_home' => string 'Home'
echo $meta_boxes_fields->head_home;
echo $meta_boxes_fields->description_home;
Dump of Extended $meta_boxes_fields in About page
public 'head_about' => string 'Home'
public 'description_about' => string '<p> About Content</p>'
public 'gallery' =>
array
0 => string '56' (length=2)
1 => string '44' (length=2)
2 => string '42' (length=2)
3 => string '18' (length=2)
echo $meta_boxes_fields->head_about;
echo $meta_boxes_fields->description_about;
$gallery = $meta_boxes_fields->gallery;
I want like this. Is it possible ?
Thank you very much.
Hi,
Yes, you can extend the meta box objects. Please use this snippet to get all meta box instances:
$meta_boxes = rwmb_get_registry( 'meta_box' )->get( 'all' );
foreach ( $meta_boxes as $meta_box ) {
// Do whatever you want
}
Then you can filter, add/remove more settings to meta boxes. The meta box registry contains all references to real meta box objects. So be careful. Because what you change will affect the whole code.
PS: Using the filter rwmb_meta_boxes
just gives you a copy of array of meta box settings, not real meta box objects.
Hi,
Thanx Anh,
$meta_boxes = rwmb_get_registry( 'meta_box' )->get( 'all' );
$meta_boxes returning boolean false,
Also how can i get meta values using page_id in specific pages
Thanx
UG
Hi,
Can you check if you register meta boxes under any condition such as is_admin()
or inside a hook? It's required to put the code that register meta boxes (add_filter('rwmb_meta_boxes', ...)
) not inside any condition.
The rwmb_get_registry
returns a registry, e.g. a storage, of all registered meta box objects. You can use that registry to get all meta boxes via get( 'all' )
method.
The statement:
$meta_boxes = rwmb_get_registry( 'meta_box' )->get( 'all' );
actually means:
$meta_box_registry = rwmb_get_registry( 'meta_box' );
$meta_boxes = $meta_box_registry->get( 'all );
To get meta values for a specific page ID, please use the 3rd parameter in the helper functions:
$value = rwmb_meta( 'field_id', '', $page_id );
For more info, please read the docs.