List all Meta Fields for current post

Support General List all Meta Fields for current post

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #3665
    carassiuscarassius
    Participant

    Is there a way to output an array of all Meta Boxes used in a post so I can have it in a select field?

    #3666
    carassiuscarassius
    Participant

    As an example of how I am trying to work it

    function bs_get_meta_fields() {
            
        $meta = array(
            '' => 'Choose Meta Field'
        );
            
        $fields = rwmb_meta(); /* doesnt work */
            
        foreach ( $fields as $field ) {
                
            $meta[$field->id] = $field->name;
                
        }
    
        return $meta;
            
    }
    #3670
    Anh TranAnh Tran
    Keymaster

    You can use this snippet:

    $post_type = get_post_type();
    $meta = array(
        '' => 'Choose Meta Field',
    );
    $meta_boxes = RWMB_Core::get_meta_boxes();
    foreach ( $meta_boxes as $meta_box ) {
        if ( $post_type != $meta_box['post_types'] && ! in_array( $post_type, $meta_box['post_types'] ) ) {
            continue;
        }
        foreach ( $meta_box['fields'] as $field ) {
            if ( ! empty( $field['id'] ) ) {
                $meta[$field['id']] = $field['name'];
            }
        }
    }
    #3673
    carassiuscarassius
    Participant

    Have some work to do on this project involoving some custom code for metabox, if interested in being hired again, let me know.

    #3684
    Anh TranAnh Tran
    Keymaster

    Just sent you an email 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘List all Meta Fields for current post’ is closed to new replies.