Viewing 4 reply threads
  • Author
    Posts
    • #4311

      Hello,

      I’m trying to insert some terms into a custom taxonomy. I want the terms to be pre-populated for the CPT and the client cannot add terms. I have used the following code to but the terms are not showing up. Any idea of what I’m doing wrong?

      add_filter('piklist_taxonomies', 'mhs_add_gender_tax');
       function mhs_add_gender_tax($taxonomies)
       {
         $taxonomies[] = array(
            'post_type' => 'mhs_horses'
            ,'name' => 'mhs_gender_tax'
            ,'show_admin_column' => true
            ,'configuration' => array(
              'hierarchical' => true
              ,'labels' => piklist('taxonomy_labels', 'Gender')
              ,'hide_meta_box' => false
              ,'show_ui' => true
              ,'query_var' => true
              ,'rewrite' => array( 
                'slug' => 'gender' 
              )
            )
          );
      return $taxonomies;
      }
      
      function gender_insert_terms () {
        if ( !term_exists( 'Mare', 'mhs_gender_tax' ) ) {
          wp_insert_term (
            'Mare',
            'mhs_gender_tax',
            array(
              'description' => "Mares",
              'slug' => 'mares'
            ) );
        }
      }
      
      add_action( 'init', 'gender_insert_terms');
    • #4312

      Oh, I will also need to add ‘Stallion’ and ‘Gelding’

    • #4313
      Steve
      Keymaster

      @txhorselady– If you increase the priority on init it will work:

      add_action('init', 'gender_insert_terms', 99);
      
    • #4315

      Your awesome Steve, Thank You!!!

    • #4322
      Steve
      Keymaster

      Always happy to help. Closing ticket

Viewing 4 reply threads
  • The topic ‘Insert Terms Into Custom Taxonomy’ is closed to new replies.