Custom Fields
Re-Envisioned
Support General Get all field values into a public array and filter with page id in front end

  • Creator
    Topic
  • #10707
    uththamag
    Participant

    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() );

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #10711
    Anh Tran
    Keymaster

    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.

    #10719
    uththamag
    Participant

    Hi,

    Thanx Anh,

    $meta_boxes = rwmb_get_registry( ‘meta_box’ )->get( ‘all’ );

    $meta_boxes returning boolean false,

    1. Can you explain this – “->get( ‘all’ );”
    2. Also how can i get meta values using page_id in specific pages

    Thanx
    UG

    #10727
    Anh Tran
    Keymaster

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get all field values into a public array and filter with page id in front end’ is closed to new replies.