• ResolvedPlugin Author ravasol

    (@ravasol)


    Please add something like ‘$tp = $wpdb->prefix’ to accomodate setups with db prefix different from default. Took me a while to figure out why it wasint working for me >.<

    function get_category_tags($args) {
      global $wpdb;
      $tp = $wpdb->prefix;
      $tags = $wpdb->get_results
      ("
        SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
        FROM
          ${tp}posts as p1
          LEFT JOIN ${tp}term_relationships as r1 ON p1.ID = r1.object_ID
          LEFT JOIN ${tp}term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
          LEFT JOIN ${tp}terms as terms1 ON t1.term_id = terms1.term_id,
    
          ${tp}posts as p2
          LEFT JOIN ${tp}term_relationships as r2 ON p2.ID = r2.object_ID
          LEFT JOIN ${tp}term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
          LEFT JOIN ${tp}terms as terms2 ON t2.term_id = terms2.term_id
        WHERE
          t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.name = '$args' AND
          t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
          AND p1.ID = p2.ID
        ORDER by tag_name
      ");
      $count = 0;
      foreach ($tags as $tag) {
        $tags[$count]->tag_link = get_tag_link($tag->tag_id);
        $count++;
      }
      return $tags;

    http://wordpress.org/extend/plugins/one-page-portfolio/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Pengyi Wang

    (@rocwing)

    Hi,
    I have updated the version, thank you for your help!

    rocwing

    Hello Guys, I hope its OK that I post my question here. I am trying to modify this script to show taxonomys inside another taxonomy.

    This is what I got, any help would be great:

    function get_tax_tags($args) {
    	global $wpdb;
            $tp = $wpdb->prefix;
    	$tags = $wpdb->get_results
    	("
    		SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
    		FROM
    			wp_posts as p1
    			LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
    			LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
    			LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,
    
    			wp_posts as p2
    			LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
    			LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
    			LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
    		WHERE
    			t1.taxonomy = 'rea' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
    			t2.taxonomy = 'outlet' AND p2.post_status = 'publish'
    			AND p1.ID = p2.ID
    		ORDER by tag_name
    
    	");
    	$count = 0;
    	foreach ($tags as $tag) {
    		$tags[$count]->tag_link = get_tag_link($tag->tag_id);
    		$count++;
    	}
    	return $tags;
    }

    And my “show” function:

    function yrken15() {
    
    if ( is_tax( 'rea' )) {
    global $wp_query;
    $tax = $wp_query->queried_object;
    
    	print "\n" . '<ul class="featured-brands25" style="list-style: none;">';
    echo '<h3>Du kan handla ' . strtolower(single_cat_title( '', false )) . ' från följande varumärken</h3>'; 
    
    $the_id = $tax->term_id;
    
    echo $the_id;
    $tags = get_tax_tags($the_id);
    
    sort($tags);
    
    foreach ($tags as $tag) {
    
    print "\n" . '<li>';
    			print "\n\t" . '<p style="text-align: center;"><a class="classname2" href="' . get_home_url() . '/outlet/' . strtolower(str_replace(' ', '-', $tag->tag_name)) . '/">' . strtolower($tag->tag_name) . '</a></p>';
    			print "\n" . '</li>';
    
    }
    	print "\n" . '</ul>';
    
    }
    
    else if ( is_tax( 'outlet' )) { 
    
    }
    
    else { 
    
    }
    }

    Getting the tax->term_id works fine (as the echoing line will tell) but no results shows up, any idea why? Also I found that when I am using the original setting with category and tags, the function works on some of my webhosts but not on other, why would that be?

    Thank you guys in advance!

    Regards Fredrik from Sweden

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

The topic ‘get_category_tags function clean up’ is closed to new replies.