wordpress custom field as tags

Discussion in 'PHP' started by kainrazial, Jul 15, 2010.

  1. #1
    any one can help he, i wanna to use tags as custom field, how this can be done, is their any functions avilable for tat, if so how i can do this
     
    kainrazial, Jul 15, 2010 IP
  2. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not quite sure what you mean here. You can use tags however you want, but Wordpress already has custom fields in the form of meta data.

    Either way, heres a function I made to extract all the tags from a specific post:
    
    <?php
    /*
     * getAllTags() returns an array of all tags associated 
     * with a post/page or false if there are none.
     * 
     * For use in wordpress templates/plugins
     */
    if ( ! function_exists( 'getAllTags' ) ):   
    function getAllTags($id = 0) { 
        global $wpdb;
        
        if ($id == 0) {
            global $wp_query;
            $postID = $wp_query->post->ID;
        }
        
        $sql = 'SELECT c.name
                FROM wp_term_relationships AS a
                LEFT OUTER JOIN wp_term_taxonomy AS b ON a.term_taxonomy_id = b.term_taxonomy_id
                LEFT OUTER JOIN wp_terms AS c ON b.term_id = c.term_id
                WHERE b.taxonomy = "post_tag" AND a.object_id = ' . $postID;
                
        if (!$query = mysql_query($sql)) return false;                                      
                             
        $returnArray = array();
        while ($row = mysql_fetch_row($query)) $returnArray[] = $row[0];    
        return $returnArray;    
    }
    endif;
    ?>
    
    PHP:
     
    Deacalion, Jul 15, 2010 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    Wordpress already has custom tags, no need to use confusing functions, it's already built in. Here's how:
    Alternately, you can google for more. :)
     
    Rainulf, Jul 15, 2010 IP