WordPress.org

Plugin Directory

Changeset 525455


Ignore:
Timestamp:
03/30/12 18:05:48 (2 years ago)
Author:
Omicron7
Message:

Version 1.1

Location:
advanced-custom-fields-taxonomy-field-add-on/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • advanced-custom-fields-taxonomy-field-add-on/trunk/README.md

    r502765 r525455  
    1313The taxonomy field provides a dropdown (select or multi-select) of taxonomy terms (categories, tags, custom taxonomies...) 
    1414and the ability to map the selected terms to the post. The post type must support the taxonomy for the mapping to work. 
    15 The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The get_value() api returns 
    16 an array of the selected term ids. 
     15The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The `get_value()` api returns 
     16a list of taxonomy links similar to WordPress `get_the_term_list()`. 
    1717 
    1818### Source Repository on GitHub 
    1919https://github.com/GCX/acf-taxonomy-field 
    2020 
    21 ### Bugs or Suggestions 
     21### Bugs, Questions or Suggestions 
    2222https://github.com/GCX/acf-taxonomy-field/issues 
    2323 
     
    4848* Add ability to add new terms to a taxonomy 
    4949* Add more term selection methods (checkboxes, token input). 
    50 * Improve the `get_value()` api call to return html using `the_terms()` WordPress method. 
  • advanced-custom-fields-taxonomy-field-add-on/trunk/readme.txt

    r502765 r525455  
    44Requires at least: 3.0 
    55Tested up to: 3.3.1 
    6 Stable tag: 1.0 
     6Stable tag: 1.1 
    77 
    88Adds a Taxonomy Field to Advanced Custom Fields. Select one or more taxonomy terms and assign them to the post. 
     
    1616The taxonomy field provides a dropdown (select or multi-select) of taxonomy terms (categories, tags, custom taxonomies...) 
    1717and the ability to map the selected terms to the post. The post type must support the taxonomy for the mapping to work. 
    18 The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The get_value() api returns 
    19 an array of the selected term ids. 
     18The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The `get_value()` api returns 
     19a list of taxonomy links similar to WordPress `get_the_term_list()`. 
    2020 
    2121= Source Repository on GitHub = 
    2222https://github.com/GCX/acf-taxonomy-field 
    2323 
    24 = Bugs or Suggestions = 
     24= Bugs, Questions or Suggestions = 
    2525https://github.com/GCX/acf-taxonomy-field/issues 
    2626 
     
    2828* Add ability to add new terms to a taxonomy 
    2929* Add more term selection methods (checkboxes, token input). 
    30 * Improve the `get_value()` api call to return html using `the_terms()` WordPress method. 
    3130 
    3231== Installation == 
     
    5857== Changelog == 
    5958 
     59= 1.1 = 
     60* Improved get_value API call. Using `get_value()` now returns a string of term links. Similar to WordPress `get_the_term_list()`. 
     61* Fixed an issue with terms not being pre-selected when editing a post. 
     62* Fixed a localization variable name typo. 
     63 
    6064= 1.0 = 
    6165* Initial Release 
  • advanced-custom-fields-taxonomy-field-add-on/trunk/taxonomy-field.php

    r502765 r525455  
    66* Author:      Brian Zoetewey 
    77* Author URI:  https://github.com/GCX 
    8 * Version:     1.0 
     8* Version:     1.1 
    99* Text Domain: acf-taxonomy-field 
    1010* Domain Path: /languages/ 
     
    107107         
    108108        $this->name  = 'taxonomy-field'; 
    109         $this->title = __( 'Taxonomy', $this->l10n_doamin ); 
     109        $this->title = __( 'Taxonomy', $this->l10n_domain ); 
    110110         
    111111        add_action( 'admin_print_scripts', array( &$this, 'admin_print_scripts' ), 12, 0 ); 
     
    174174        $terms = get_terms( $field['taxonomy'], array( 'hide_empty' => false ) ); 
    175175        $value = $field[ 'value' ]; 
    176          
     176 
    177177        if( in_array( $field[ 'input_type' ], array( 'select', 'multiselect' ) ) ) : 
    178178        ?> 
    179179            <select name="<?php echo $field[ 'name' ]; ?>[]" id="<?php echo $field[ 'name' ]; ?>" class="<?php echo $field[ 'class' ]; ?>" <?php echo ( $field[ 'input_type' ] == 'multiselect' ) ? 'multiple="multiple" size="' . $field[ 'input_size' ] . '"' : ''; ?>> 
    180180                <?php foreach( $terms as $term ) : ?> 
    181                     <option value="<?php echo $term->term_id; ?>" <?php selected( in_array( $term->term_id, $value, true ) ); ?>><?php echo $term->name; ?></option> 
     181                    <option value="<?php echo $term->term_id; ?>" <?php selected( in_array( (int) $term->term_taxonomy_id, $value ) ); ?>><?php echo $term->name; ?></option> 
    182182                <?php endforeach; ?> 
    183183            </select> 
     
    334334     */ 
    335335    public function get_value_for_api( $post_id, $field ) { 
    336         return parent::get_value_for_api($post_id, $field); 
     336        $this->set_field_defaults( $field ); 
     337        //If terms are set on the post, we can let WordPress create the list 
     338        if( $field[ 'set_post_terms' ] ) { 
     339            return get_the_term_list( $post_id, $field[ 'taxonomy' ] ); 
     340        } 
     341         
     342        //Otherwise, loop through the terms 
     343        $value = parent::get_value_for_api($post_id, $field); 
     344        if( empty( $value ) ) 
     345            return false; 
     346         
     347        $term_links = array(); 
     348        foreach( $value as $term_id ) { 
     349            $term_id = intval( $term_id ); 
     350            $term = get_term( $term_id ); 
     351            $link = get_term_link( $term, $taxonomy ); 
     352            if( !is_wp_error( $link ) ) 
     353                $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>'; 
     354        } 
     355        if( empty( $term_links ) ) 
     356            return false; 
     357         
     358        //Allow plugins to modify 
     359        $term_links = apply_filters( "term_links-{$field[ 'taxonomy' ]}", $term_links ); 
     360         
     361        return join( '', $term_links ); 
    337362    } 
    338363} 
Note: See TracChangeset for help on using the changeset viewer.