• Resolved kthakk4

    (@kthakk4)


    There is a wp plugin that displays lists categories in a multiple columns on a page. I want to modify this plugin so as to do the same with tags instead of category.

    The original code (with category) uses the following query to obtain categories:

    $cat_list = (array)$wpdb->get_results("
    			SELECT {$tp}terms.term_id as cat_ID,
    				{$tp}terms.name as cat_name
    			FROM {$tp}terms, {$tp}term_taxonomy, {$tp}term_relationships, {$tp}posts
    			WHERE {$tp}term_taxonomy.taxonomy = 'category'
    			AND {$tp}term_taxonomy.term_id = {$tp}terms.term_id
    			AND {$tp}term_taxonomy.term_taxonomy_id = {$tp}term_relationships.term_taxonomy_id
    			AND {$tp}term_relationships.object_id = {$tp}posts.ID
    			AND {$tp}terms.term_id = {$tp}term_taxonomy.term_id
    			{$exclude_sql}
    			GROUP BY cat_name
    			ORDER BY cat_name
    		");

    Obviously, my intuition to replace all the cat references with tag reference and change the code. This is my modified code:

    $tag_list = (array)$wpdb->get_results("
    			SELECT {$tp}terms.term_id as tag_ID,
    				{$tp}terms.name as tag_name
    			FROM {$tp}terms, {$tp}term_taxonomy, {$tp}term_relationships, {$tp}posts
    			WHERE {$tp}term_taxonomy.taxonomy = 'tag'
    			AND {$tp}term_taxonomy.term_id = {$tp}terms.term_id
    			AND {$tp}term_taxonomy.term_taxonomy_id = {$tp}term_relationships.term_taxonomy_id
    			AND {$tp}term_relationships.object_id = {$tp}posts.ID
    			AND {$tp}terms.term_id = {$tp}term_taxonomy.term_id
    			{$exclude_sql}
    			GROUP BY tag_name
    			ORDER BY tag_name
    		");

    However this results in a null string. Any idea how I can fix this?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kthakk4

    (@kthakk4)

    I figured it out. In the following line, I needed ‘post_tag’ instead of just ‘tag’

    WHERE {$tp}term_taxonomy.taxonomy = 'tag'

    What plugin you are talking about?

    I’ve had two plugins for tags but since I’ve upgraded to WP 2.8 none of that plugins are working.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting Tags using mySQL query’ is closed to new replies.