Skip to content

Instantly share code, notes, and snippets.

@obodohub obodohub/member-tags.php
Last active Aug 3, 2018

Embed
What would you like to do?
Member Tags Metabox with Validation Code
/******************************************************************
Member Tag Fields
******************************************************************/
if ( ! function_exists('obh_member_tags') ) {
function obh_member_tags( $meta_boxes ) {
global $wpdb;
$prefix = 'obh_member_';
$meta_boxes[] = array(
'id' => 'obh_member_tags',
'title' => esc_html__( 'Member Tags', 'obh' ),
'post_types' => array( 'obh_member' ),
'context' => 'normal',
'autosave' => false,
'fields' => array(
array(
'id' => $prefix . 'membership_tags',
'name' => esc_html__( 'Membership Tags', 'obh' ),
'type' => 'taxonomy',
'placeholder' => esc_html__( 'Select a Membership Tag', 'obh' ),
'taxonomy' => 'obh_member_membership_tags',
'field_type' => 'checkbox_list',
//'required' => true,
'inline' => false,
'columns' => 3,
'query_args' => array(
'meta_query' => array(
'key' => 'obh_active_tax_selector',
'value' => 'yes',
),
'orderby' => 'meta_value_num',
'meta_key' => 'obh_tax_order',
'order' => 'ASC',
),
),
array(
'id' => $prefix . 'cohort_tags',
'name' => esc_html__( 'Cohort Tags', 'obh' ),
'type' => 'taxonomy',
'placeholder' => esc_html__( 'Select a Cohort Tag', 'obh' ),
'taxonomy' => 'obh_member_cohort_tags',
'field_type' => 'checkbox_list',
//'required' => true,
'inline' => false,
'columns' => 3,
'query_args' => array(
'meta_query' => array(
'key' => 'obh_active_tax_selector',
'value' => 'yes',
),
'orderby' => 'meta_value_num',
'meta_key' => 'obh_tax_order',
'order' => 'ASC',
),
),
array(
'id' => $prefix . 'needs_tags',
'name' => esc_html__( 'Needs Tags', 'obh' ),
'type' => 'taxonomy',
'placeholder' => esc_html__( 'Select a Needs Tag', 'obh' ),
'taxonomy' => 'obh_member_needs_tags',
'field_type' => 'checkbox_list',
//'required' => true,
'inline' => false,
'columns' => 3,
'query_args' => array(
'meta_query' => array(
'key' => 'obh_active_tax_selector',
'value' => 'yes',
),
'orderby' => 'meta_value_num',
'meta_key' => 'obh_tax_order',
'order' => 'ASC',
),
),
array(
'id' => $prefix . 'grant_tags',
'name' => esc_html__( 'Grant Tags', 'obh' ),
'type' => 'taxonomy',
'messsage' => esc_html__( 'Select a Grant Tag', 'obh' ),
'taxonomy' => 'obh_member_grant_tags',
'field_type' => 'checkbox_list',
//'required' => true,
'inline' => false,
'columns' => 3,
'query_args' => array(
'meta_query' => array(
'key' => 'obh_active_tax_selector',
'value' => 'yes',
),
'orderby' => 'meta_value_num',
'meta_key' => 'obh_tax_order',
'order' => 'ASC',
),
),
'validation' => array(
'rules' => array(
'obh_member_membership_tags' => array(
'required' => true,
),
'obh_member_cohort_tags' => array(
'required' => true,
),
'obh_member_needs_tags' => array(
'required' => true,
),
'obh_member_grant_tags' => array(
'required' => true,
),
),
'messages' => array(
'obh_member_membership_tags' => array(
'required' => 'You must select a tag to proceed',
),
'obh_member_cohort_tags' => array(
'required' => 'You must select a tag to proceed',
),
'obh_member_needs_tags' => array(
'required' => 'You must select a tag to proceed',
),
'obh_member_grant_tags' => array(
'required' => 'You must select a tag to proceed',
),
)
)
)
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'obh_member_tags' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.