Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Extend RW_Meta_Box class
- * Add field types: 'taxonomy', 'post_type'
- */
- class RW_Meta_Box_Extend extends RW_Meta_Box {
- function add_missed_values() {
- parent::add_missed_values();
- // add 'multiple' option to taxonomy field with checkbox_list type
- foreach ($this->_meta_box['fields'] as $key => $field) {
- if ('taxonomy' == $field['type'] && 'checkbox_list' == $field['options']['type'] || 'custom_post' == $field['type'] && 'checkbox_list' == $field['options']['type']) {
- $this->_meta_box['fields'][$key]['multiple'] = true;
- }
- }
- }
- // show taxonomy list
- function show_field_taxonomy($field, $meta) {
- global $post;
- if (!is_array($meta)) $meta = (array) $meta;
- $this->show_field_begin($field, $meta);
- $options = $field['options'];
- $terms = get_terms($options['taxonomy'], $options['args']);
- // checkbox_list
- if ('checkbox_list' == $options['type']) {
- foreach ($terms as $term) {
- echo "<input type='checkbox' name='{$field['id']}[]' value='$term->slug'" . checked(in_array($term->slug, $meta), true, false) . " /> $term->name<br/>";
- }
- }
- // select
- else {
- echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">";
- foreach ($terms as $term) {
- echo "<option value='$term->slug'" . selected(in_array($term->slug, $meta), true, false) . ">$term->name</option>";
- }
- echo "</select>";
- }
- $this->show_field_end($field, $meta);
- }
- // show custom post list
- function show_field_custom_post($field, $meta) {
- global $post;
- if (!is_array($meta)) $meta = (array) $meta;
- $this->show_field_begin($field, $meta);
- $options = $field['options'];
- $customs = get_posts($options['args']);
- // checkbox_list
- if ('checkbox_list' == $options['type']) {
- foreach ($customs as $custom) {
- $galleryurl = wp_get_attachment_image_src( get_post_thumbnail_id( $custom->ID ), 'full');
- echo "<input type='checkbox' name='{$field['id']}[]' value='$custom->post_title'" . checked(in_array($custom->post_title, $meta), true, false) . " />$custom->post_title<br/>";
- }
- }
- // select
- else {
- echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">";
- foreach ($customs as $custom) {
- echo "<option value='$custom->post_title'" . selected(in_array($custom->post_title, $meta), true, false) . ">$custom->post_title</option>";
- }
- echo "</select>";
- }
- $this->show_field_end($field, $meta);
- }
- }
- // Show post_type meta box
- array(
- 'id' => $prefix . 'custom',
- 'type' => 'custom_post',
- 'options' => array(
- 'type' => 'checkbox_list',
- 'args' => array( // arguments for get posts http://goo.gl/OVtT
- 'post_type' => 'artist',
- 'posts_per_page' => 3
- )
- ),
- 'multiple' => true
- )
- // Renamed the class here with the new one
- foreach ($meta_boxes as $meta_box) {
- $my_box = new RW_Meta_Box_Extend($meta_box);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement