Reusable set of fields #1147
Unanswered
brianshepherd
asked this question in
Q&A
Replies: 1 comment
-
@brianshepherd you could generate the fields in a function. Example: function create_section_settings_complex_field(string $context) {
return Field::make( 'complex', 'crb_section_settings_' . $context )
->add_fields( 'photograph', array(
Field::make( 'text', 'caption', __( 'Caption' ) ),
Field::make( 'image', 'image', __( 'Image' ) )
->set_value_type( 'url' ),
) )
->add_fields( 'movie', array(
Field::make( 'text', 'length', __( 'Length' ) ),
Field::make( 'text', 'title', __( 'Title' ) ),
Field::make( 'file', 'video', __( 'Video' ) )
->set_value_type( 'url' ),
) );
}
/* ... */
Container::make( 'post_meta', 'Custom Data' )
->where( 'post_type', '=', 'page' )
->add_fields( array(
create_section_settings_complex_field('page_media');
));
Container::make( 'term_meta', __( 'Category Properties' ) )
->where( 'term_taxonomy', '=', 'category' )
->add_fields( array(
create_section_settings_complex_field('category_media');
) ); Does this work for you? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to create a set of complex fields and reuse them. An example would be a "section settings" complex field that could be included within another set of complex fields used for page sections.
Beta Was this translation helpful? Give feedback.
All reactions