项目作者: CMB2

项目描述 :
Originally created for Post Status (https://poststatus.com/) to associate footnotes with notes, This CMB2 addon allows you to use CMB2 group fields to manage custom post type entries.
高级语言: PHP
项目地址: git://github.com/CMB2/cmb2-group-map.git
创建时间: 2017-01-23T14:13:24Z
项目社区:https://github.com/CMB2/cmb2-group-map

开源协议:

下载


CMB2 Group Map

Originally created for Post Status to associate footnotes with notes, This CMB2 addon allows you to use CMB2 group fields to manage custom post type entries.

You will either need to clone and then run composer install in this plugin’s directory to get the required dependencies, or simply download the compiled zip.

A few details:

  • To specify the post type destination, add a 'post_type_map' parameter to your group field parameters.
  • To set the default WordPress post fields (e.g. the post content, title, etc), you need to set the 'id' parameter to the same value as the wp_posts database column name. So for the content, the 'id' parameter would be 'post_content', or for the title, 'post_title'.
  • To set taxonomy terms for the connected post-type posts, use one of the taxonomy_* field types.

Example

You need to include this library:

  1. require_once( 'cmb2-group-map/cmb2-group-map.php' );

Then setup a CMB2 metabox with a grouped field:

  1. // Standard CMB2 registration.
  2. $cmb = new_cmb2_box( array(
  3. 'id' => 'footnotes',
  4. 'title' => 'Footnotes',
  5. 'object_types' => array( 'post' ),
  6. ) );
  7. // This is our group field registration. It's mostly standard.
  8. $group_field_id = $cmb->add_field( array(
  9. 'id' => 'footnotes_ids',
  10. 'type' => 'group',
  11. // This is a custom property, and should specify
  12. // the destination post-type.
  13. 'post_type_map' => 'footnotes',
  14. 'description' => 'Manage/add connected footnotes',
  15. 'options' => array(
  16. 'group_title' => 'Footnote {#}',
  17. 'add_button' => 'Add New Footnote',
  18. 'remove_button' => 'Remove Footnote',
  19. 'sortable' => true,
  20. ),
  21. ) );
  22. // by using 'post_title' as the id, this will be the
  23. // value stored to the destination post-type's title field.
  24. $cmb->add_group_field( $group_field_id, array(
  25. 'name' => 'Title',
  26. 'id' => 'post_title',
  27. 'type' => 'text',
  28. ) );
  29. // by using 'post_content' as the id, this will be the
  30. // value stored to the destination post-type's content field.
  31. $cmb->add_group_field( $group_field_id, array(
  32. 'name' => 'Content',
  33. 'id' => 'post_content',
  34. 'type' => 'textarea_small',
  35. ) );
  36. // This field will be stored as post-meta against
  37. // the destination post-type.
  38. $cmb->add_group_field( $group_field_id, array(
  39. 'name' => 'Color meta value',
  40. 'id' => 'footnote_color',
  41. 'type' => 'colorpicker',
  42. ) );
  43. // This field will be stored as category terms
  44. // against the destination post-type.
  45. $cmb->add_group_field( $group_field_id, array(
  46. 'name' => 'Categories',
  47. 'id' => 'category',
  48. 'taxonomy' => 'category',
  49. 'type' => 'taxonomy_multicheck',
  50. ) );

Screenshots

  1. Group Field Display
    Group Field Display

  2. Group pulled from custom-post-type post
    Group pulled from custom-post-type post

  3. Post-select search modal
    Post-select search modal