여기서 말한 것을 생각해 보면 PHP에 익숙하다고 가정합니다. 좋은 소식은 PHP 지식이 여기에 편리하게 올 것입니다. 이제 register_post_type 함수의 새로운 기능을 배울 차례입니다. 즉, register_meta_box_cb
매개 변수입니다. 이렇게하면 cpt add 및 edit 페이지에 metabox를 추가하기 위해 호출 할 함수를 정의 할 수 있습니다. 예를 들어, 여기에 추가 매개 변수 (국제 식품에서 직접 촬영)를 CPT이다
function my_beta_box_function(){
add_meta_box(
'myplugin_sectionid',
__('My Post Section Title', 'myplugin_textdomain'),
'myplugin_inner_custom_box',
'book'
);
}
add_meta_box : 이제 메타 박스 (CB) 기능이 정의되어 있음을
add_action('init', 'codex_custom_init');
function codex_custom_init()
{
$labels = array(
'name' => _x('Books', 'post type general name'),
'singular_name' => _x('Book', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Book'),
'edit_item' => __('Edit Book'),
'new_item' => __('New Book'),
'view_item' => __('View Book'),
'search_items' => __('Search Books'),
'not_found' => __('No books found'),
'not_found_in_trash' => __('No books found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Books'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'register_meta_box_cb' => 'my_meta_box_function',
'supports' => array('title','editor','author','thumbnail','excerpt','comments')
);
register_post_type('book',$args);
}}
을, 그것을 좋아 사용 당신을위한 메타 박스를 정의하고 메타 옥시 내에서 내용을 만드는 함수를 제공합니다. 이 경우 코드는 myplugin_inner_custom_box
함수를 참조합니다. 메타 박스 추가에 대한 자세한 내용은 http://codex.wordpress.org/Function_Reference/add_meta_box을 참조하십시오. 그래서, 우리가 지금 기능을 정의하여 콘텐츠를 추가해야합니다
function myplugin_inner_custom_box()
{
// Everything here would appear in the meta box
}
이 시점에서 제출 게시물에 처리 할 수있는 HTML 양식을 만들 수있는 당신의 PHP 지식을 활용할 수 있습니다. 다른 PHP 응용 프로그램에서와 마찬가지로 + 버튼을 추가하고 PHP를 사용할 수 있습니다. 나는 당신이 그것을 할 수 있다고 가정 할 것이므로 이것을하는 방법에 가지 않을 것입니다. 나는 실제로 이런 대사 증후군을 만들었고 내가 게시 한 기능을 알고 난 후에는 PHP 지식에 의존 할 수있었습니다. 이 마지막 부분은 입력 내용을 저장하는 것입니다. 마지막으로
/* Do something with the data entered */
add_action('save_post', 'myplugin_save_postdata');
/* When the post is saved, saves our custom data */
function myplugin_save_postdata($post_id) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if (!wp_verify_nonce($_POST['myplugin_noncename'], plugin_basename(__FILE__)))
return $post_id;
// Check permissions
if ('page' == $_POST['post_type'])
{
if (!current_user_can('edit_page', $post_id))
return $post_id;
}
else
{
if (!current_user_can('edit_post', $post_id))
return $post_id;
}
// OK, we're authenticated: we need to find and save the data
$mydata = $_POST['myplugin_new_field'];
update_post_meta('my_field', $mydata);
return $mydata;
}
, 저장 기능에 대한 메모 : 루틴 및 save_post 행동을 저장을 정의하는 기능을 사용하면 데이터를 저장하기 위해 PHP 지식을 사용할 수 있습니다. 입력란의 이름을 배열 값 (예 :, docs[]
), $ _POST [ 'docs'] 값은 배열이됩니다. 다행히 WP의 update_post_meta
기능은 배열 입력을 처리하기위한 모든 설정입니다. 그것은 그것을 serialize하고 그것을 입력합니다. 호환되는 get_post_meta
기능을 사용하면 데이터를 준비 할 수 있도록 어레이를 직렬화 해제합니다.
행운을 빈다.
와우 감사합니다. 이 단계를 단계별로 읽어 보겠습니다. 다시 한 번 감사드립니다! – drpcken
그래서 이러한 metaboxes 오른쪽 사용자 정의 필드에 연결되어 있지 않습니다? 나는 metaboxes에 대한 가치에 대한 내 자신의 테이블을 만들고 게시물 ID에 링크해야할까요? – drpcken
오, 기다려 봐요, 보시다시피, 맞춤형 메타 박스를 바로 추가하고 있습니다! 아주 좋아! 나는 이걸로 일할거야. 고맙습니다! – drpcken