Support

Account

Home Forums ACF PRO Taxonomy field – multiple taxonomies

Solved

Taxonomy field – multiple taxonomies

  • Hi

    Is there any type of field that’ll show terms list of multiple custom taxonomies?
    Unlike the taxonomy field that will only let me choose one taxonomy.

    – Ido

  • Ended up changing the taxonomy field (taxonomy.php):

    Lines 115-134:

    $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
    $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id'] );
    $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id'] );
    			
    // get terms
    $terms = get_terms( $field['taxonomy'], $args );
    		
    // sort into hierachial order!
    if( is_taxonomy_hierarchical( $field['taxonomy'] ) ) {
    // this will fail if a search has taken place because parents wont exist
    if( empty($args['search']) ) {
    $terms = _get_term_children( 0, $terms, $field['taxonomy'] );
    }
    }

    Replaced with:

    $all_taxonomies = get_taxonomies();
    $taxonomies = array();
    
    foreach ($all_taxonomies as $taxonomy) {
    if ($taxonomy != 'post_tag' && $taxonomy != 'nav_menu' && $taxonomy != 'link_category' && $taxonomy != 'post_format') {
    array_push($taxonomies, $taxonomy);
    }
    }
    		
    $args = array('orderby'           => 'name', 'order'             => 'ASC', 'hide_empty'        => false); 
    
    $terms = get_terms($taxonomies, $args);

    And Line 489:

    $terms = $this->get_terms( $field['value'], $field['taxonomy'] );

    Replaced with:

    $all_taxonomies = get_taxonomies();
    $taxonomies = array();
    
    foreach ($all_taxonomies as $taxonomy) {
    if ($taxonomy != 'post_tag' && $taxonomy != 'nav_menu' && $taxonomy != 'link_category' && $taxonomy != 'post_format') {
    array_push($taxonomies, $taxonomy);
    }
    }
    		
    $args = array('orderby'           => 'name', 'order'             => 'ASC', 'hide_empty'        => false); 
    
    $terms = get_terms($taxonomies, $args);

    The following will output all terms from the ‘category’ taxonomy and from all other registered taxonomies.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Taxonomy field – multiple taxonomies’ is closed to new replies.