Get all field values into a public array and filter with page id in front end
- This topic has 3 replies, 2 voices, and was last updated 6 years, 8 months ago by
Anh Tran.
-
AuthorPosts
-
July 25, 2018 at 12:25 PM #10707
uththamag
ParticipantHi,
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() );
Output
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.
Home page
Dump of Extended $meta_boxes_fields in home
object(stdClass)[600]
public 'head_home' => string 'Home'public 'description_home' => string '<p> Home Content</p>'
echo $meta_boxes_fields->head_home;
echo $meta_boxes_fields->description_home;About page
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.
July 25, 2018 at 5:28 PM #10711Anh Tran
KeymasterHi,
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.July 26, 2018 at 12:45 AM #10719uththamag
ParticipantHi,
Thanx Anh,
$meta_boxes = rwmb_get_registry( 'meta_box' )->get( 'all' );
$meta_boxes returning boolean false,
- Can you explain this - "->get( 'all' );"
-
Also how can i get meta values using page_id in specific pages
Thanx
UGJuly 26, 2018 at 11:25 AM #10727Anh Tran
KeymasterHi,
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 viaget( '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.
-
AuthorPosts
- The topic ‘Get all field values into a public array and filter with page id in front end’ is closed to new replies.