Justin Sternberg on "save new post by cmb2_get_metabox_form on frontpage"

ساخت وبلاگ

hi,

is it possible to create a new post from a custom metabox?
I'm getting the metabox form by the function cmb2_get_metabox_form

The form is shown on frontpage, but i can only edit a post and not create a new post

Code below:

//create shortcode
class CustomFrontendform { public static function init() { add_shortcode( 'cmb-form', array( __CLASS__, '_do_frontend_form_shortcode' ) ); } public static function _do_frontend_form_shortcode( $atts = array() ) { // If no metabox id is set, yell about it if ( empty( $atts['id'] ) ) { retu 'Please add an "id" attribute to specify the CMB2 form to display.'; } $metabox_id = esc_attr( $atts['id'] ); // Get our form $form = cmb2_get_metabox_form( $metabox_id ); retu $form; }
}
new CustomFrontendform();
// custom metabox
protected function hooks() { add_action( 'cmb2_init', array( __CLASS__, '_register_custommetabox_formfields' ) ); } /** * custommetabox field * Hook in and add a metabox to select templates */ public function _register_custommetabox_formfields() { new_cmb2_box( array( 'id' => Bootstrap::PREFIX . 'custommetabox', 'title' => __( 'Kleinanzeige', 'cmb2' ), 'object_types' => array( 'custom_posts', ), // Post type 'cmb_styles' => false, 'fields' => array( array( 'name' => __( 'Email', 'cmb2' ), 'id' => Bootstrap::PREFIX . 'email', 'type' => 'text_email', ), array( 'name' => __( 'Phone', 'cmb2' ), 'id' => Bootstrap::PREFIX . 'phone', 'type' => 'text', ), array( 'name' => __( 'ZIP', 'theme-domain' ), 'id' => Bootstrap::PREFIX . 'zipcode', 'type' => 'text', 'attributes' => array( 'type' => 'number', ), ), array( 'name' => __( 'Image', 'cmb2' ), 'id' => Bootstrap::PREFIX . 'image', 'type' => 'file', 'preview_size' => array( 100, 100 ), ), array( 'name' => __( 'Text', 'cmb2' ), 'id' => Bootstrap::PREFIX . 'content', 'type' => 'textarea', 'options' => array( 'textarea_rows' => 12, ) ), ) ) ); }

https://wordpress.org/plugins/cmb2/

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 348 تاريخ : جمعه 1 مرداد 1395 ساعت: 22:07