Make WordPress Core


Ignore:
Timestamp:
12/18/2008 07:12:26 PM (15 years ago)
Author:
ryan
Message:

Allow muliple tag-like taxonomies in the post editor. see #6387

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r10213 r10222  
    12071207 */
    12081208function wp_get_post_tags( $post_id = 0, $args = array() ) {
     1209    return wp_get_post_terms( $post_id, 'post_tag', $args);
     1210}
     1211
     1212/**
     1213 * Retrieve the terms for a post.
     1214 *
     1215 * There is only one default for this function, called 'fields' and by default
     1216 * is set to 'all'. There are other defaults that can be override in
     1217 * {@link wp_get_object_terms()}.
     1218 *
     1219 * @package WordPress
     1220 * @subpackage Post
     1221 * @since 2.8.0
     1222 *
     1223 * @uses wp_get_object_terms() Gets the tags for returning. Args can be found here
     1224 *
     1225 * @param int $post_id Optional. The Post ID
     1226 * @param string $taxonomy The taxonomy for which to retrieve terms. Defaults to post_tag.
     1227 * @param array $args Optional. Overwrite the defaults
     1228 * @return array List of post tags.
     1229 */
     1230function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
    12091231    $post_id = (int) $post_id;
    12101232
     
    12121234    $args = wp_parse_args( $args, $defaults );
    12131235
    1214     $tags = wp_get_object_terms($post_id, 'post_tag', $args);
     1236    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    12151237
    12161238    return $tags;
     
    14991521
    15001522    wp_set_post_categories( $post_ID, $post_category );
    1501     wp_set_post_tags( $post_ID, $tags_input );
     1523    // old-style tags_input
     1524    if ( !empty($tags_input) )
     1525        wp_set_post_tags( $post_ID, $tags_input );
     1526    // new-style support for all tag-like taxonomies
     1527    if ( !empty($tax_input) ) {
     1528        foreach ( $tax_input as $taxonomy => $tags ) {
     1529            wp_set_post_terms( $post_ID, $tags, $taxonomy );           
     1530        }
     1531    }
    15021532
    15031533    $current_guid = get_post_field( 'guid', $post_ID );
     
    16861716 */
    16871717function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
    1688 
     1718    return wp_set_post_terms( $post_id, $tags, 'post_tag', $append);
     1719}
     1720
     1721/**
     1722 * Set the terms for a post.
     1723 *
     1724 * @since 2.8.0
     1725 * @uses wp_set_object_terms() Sets the tags for the post.
     1726 *
     1727 * @param int $post_id Post ID.
     1728 * @param string $tags The tags to set for the post, separated by commas.
     1729 * @param bool $append If true, don't delete existing tags, just add on. If false, replace the tags with the new tags.
     1730 * @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise
     1731 */
     1732function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) {
    16891733    $post_id = (int) $post_id;
    16901734
     
    16941738    if ( empty($tags) )
    16951739        $tags = array();
    1696     $tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
    1697     wp_set_object_terms($post_id, $tags, 'post_tag', $append);
     1740
     1741    $tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
     1742    wp_set_object_terms($post_id, $tags, $taxonomy, $append);
    16981743}
    16991744
Note: See TracChangeset for help on using the changeset viewer.