Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Created September 18, 2019 18:03
Show Gist options
  • Select an option

  • Save carmoreira/bdbecf1db6a5df894c6b2c666b4d50b0 to your computer and use it in GitHub Desktop.

Select an option

Save carmoreira/bdbecf1db6a5df894c6b2c666b4d50b0 to your computer and use it in GitHub Desktop.
add cpt to available cpt options in advisor quiz
// Create Arrays to populate Query Builder with all available post types
add_filter( 'advq_admin_build_quiz', 'advq_coupon_cpt' );
function advq_coupon_cpt( $queryfields ) {
$fields = array();
$fields['label'] = 'Coupon';
// search
$fields['search'] = array(
'search-by' => array(
'label' => __( 'Search Keyword', 'advq' ),
),
);
// IDs array
$fields['post__in'] = array(
'post__in' => array(
'label' => __( 'IDs', 'advq' ),
),
);
// build taxonomy options
$taxonomies = get_object_taxonomies( 'shop_coupon', 'object' );
foreach ( $taxonomies as $tax ) {
if ( $tax->public == 1 ) {
$opts = array();
$terms = get_terms(
array(
'taxonomy' => $tax->name,
'hide_empty' => false,
)
);
foreach ( $terms as $key => $value ) {
$opts[ $value->term_id ] = $value->name;
}
$fields['taxonomy'][ $tax->name ]['label'] = $tax->label;
$fields['taxonomy'][ $tax->name ]['options'] = $opts;
}
}
$queryfields[ 'shop_coupon' ] = $fields;
return $queryfields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment