diff --git a/css/attached-posts-admin.css b/css/attached-posts-admin.css index 7e2f634..4c9146f 100644 --- a/css/attached-posts-admin.css +++ b/css/attached-posts-admin.css @@ -111,3 +111,8 @@ ul.hide-selected li.added{ color: #999; margin: .2em -.2em 0 1px; } + +.attached-wrap .attached.connected li input{ + display: block; + width: 60%; +} diff --git a/example-field-setup.php b/example-field-setup.php index de3d3f1..79d2e24 100644 --- a/example-field-setup.php +++ b/example-field-setup.php @@ -33,6 +33,7 @@ function cmb2_attached_posts_field_metaboxes_example() { 'type' => 'custom_attached_posts', 'options' => array( 'show_thumbnails' => true, // Show thumbnails on the left + //'show_relation' => true, // Show a text box for attached post relationship 'filter_boxes' => true, // Show a text box for filtering the results 'query_args' => array( 'posts_per_page' => 10, diff --git a/init.php b/init.php index df6dbab..391e53f 100644 --- a/init.php +++ b/init.php @@ -10,7 +10,7 @@ class WDS_CMB2_Attached_Posts_Field { const VERSION = CMB2_ATTACHED_POSTS_FIELD_VERSION; /** - * @var WDS_CMB2_Attached_Posts_Field + * @var WDS_CMB2_Attached_Posts_Field */ protected static $single_instance = null; @@ -29,6 +29,14 @@ class WDS_CMB2_Attached_Posts_Field { */ protected $do_type_label = false; + /** + * If show_relation option active relationship meta key and meta key suffic + * + * @var string + */ + protected $relation_key; + protected $meta_key_suffix = '_relation'; + /** * Creates or returns an instance of this class. * @since 0.1.0 @@ -47,6 +55,7 @@ public static function get_instance() { */ protected function __construct() { add_action( 'cmb2_render_custom_attached_posts', array( $this, 'render' ), 10, 5 ); + add_action( 'cmb2_save_field', array( $this, 'attached_posts_relation_meta' ), 10, 4 ); add_action( 'cmb2_sanitize_custom_attached_posts', array( $this, 'sanitize' ), 10, 2 ); add_action( 'cmb2_attached_posts_field_add_find_posts_div', array( $this, 'add_find_posts_div' ) ); add_action( 'cmb2_after_init', array( $this, 'ajax_find_posts' ) ); @@ -143,12 +152,13 @@ public function render( $field, $escaped_value, $object_id, $object_type, $field // Set .has_thumbnail $has_thumbnail = $this->field->options( 'show_thumbnails' ) ? ' has-thumbnails' : ''; $hide_selected = $this->field->options( 'hide_selected' ) ? ' hide-selected' : ''; + $has_relation = $this->field->options( 'show_relation' ) ? ' has-relation' : ''; if ( $filter_boxes ) { printf( $filter_boxes, 'available-search' ); } - echo '