Support Forum
Support › MB Frontend Submission › Selecting Post FormatsResolved
When adding a new post on the frontend of the site, I need to be able to select the post format the same way I can on the backend. How would I go about creating a form element for doing that? ACF has the option to choose Format in the taxonomy field, but I can't find anything similar in Meta Box other than with conditional logic, which doesn't help if I can't select a post format in the first place.
Hi,
Meta Box has not supported a field to select the post format yet. But we can create a custom field radio
with options like WordPress post formats. Sample code below:
$meta_boxes[] = [
'title' => __( 'Post Meta', 'your-text-domain' ),
'id' => 'post-meta',
'fields' => [
[
'name' => __( 'Post Format', 'your-text-domain' ),
'id' => $prefix . 'post_format',
'type' => 'radio',
'options' => [
'gallery' => __( 'Gallery', 'your-text-domain' ),
'aside' => __( 'Aside', 'your-text-domain' ),
'status' => __( 'Status', 'your-text-domain' ),
'link' => __( 'Link', 'your-text-domain' ),
'image' => __( 'Image', 'your-text-domain' ),
'quote' => __( 'Quote', 'your-text-domain' ),
'video' => __( 'Video', 'your-text-domain' ),
'audio' => __( 'Audio', 'your-text-domain' ),
'chat' => __( 'Chat', 'your-text-domain' ),
],
'inline' => false,
],
],
];
Use the action hook rwmb_{$field_id}_after_save_field to set post format after saving the custom field.
add_action( 'rwmb_post_format_after_save_field', function( $null = true, $field, $new, $old, $object_id ) {
set_post_format( $object_id, $new );
}, 10, 5 );
Ok, then we can use the function get_post_format() to get the post format as default feature post format.
This is the part I'm confused about. Where do I put action hook and function?
Hi Rebecca,
You can add the code to the file functions.php in the theme/child theme folder or use the plugin Code Snippets https://wordpress.org/plugins/code-snippets/.
Thank you.