How to Populate the Custom Taxonomy Select Box
-
Hi,
First of all thank you for publishing wonderful add-on of Contact Form 7.I followed your approach and achieved quite a lot but stuck with one thing.
I have a select box of custom post type and I am populating it by using contact form 7 hook and It list all of its option names & values.
Now I have another select box of custom taxonomy which will show options on the selection of custom post type value.
I am not sure which hook of contact form 7 I will use to populate the options of custom taxonomy.
This is my code for your reference.
add_filter( 'wpcf7_form_tag', array ( $this, 'ses_add_nmn_country_of_nomination_to_contact_form' ), 10, 2); add_filter( 'wpcf7_form_tag', array ( $this, 'ses_add_nmn_award_category_nomination_to_contact_form' ), 10, 2); public function ses_add_nmn_country_of_nomination_to_contact_form( $tag, $unused ) { if ( $tag['name'] != 'nmn_country_of_nomination' ) return $tag; $args = array ( 'post_type' => 'idcdx_country', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ); $country_list = get_posts($args); if ( !$country_list ) return $tag; foreach ( $country_list as $country ) { $tag['raw_values'][] = $country->post_title; $tag['values'][] = $country->ID; $tag['labels'][] = $country->post_title; } return $tag; } public function ses_add_nmn_award_category_nomination_to_contact_form( $tag, $unused ) { if ( $tag['name'] != 'nmn_award_category_nomination' ) return $tag; $terms = get_terms( array( 'taxonomy' => 'idcdx_category', 'hide_empty' => false, ) ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term ) { $tag['raw_values'][] = $term->name; $tag['values'][] = $term->term_id; $tag['labels'][] = $term->name; } } return $tag; }
Do you mind to help me out sort out this problem.
Thanks in Advance
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to Populate the Custom Taxonomy Select Box’ is closed to new replies.