[wp-trac] [WordPress Trac] #16253: Object term cache not working for taxonomy query page - resulting 200 queries for 10 posts

WordPress Trac wp-trac at lists.automattic.com
Sun Jan 16 00:38:44 UTC 2011


#16253: Object term cache not working for taxonomy query page - resulting 200
queries for 10 posts
-------------------------------+------------------------------
 Reporter:  badskills          |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Cache              |     Version:  3.0.4
 Severity:  major              |  Resolution:
 Keywords:  reporter-feedback  |
-------------------------------+------------------------------

Comment (by badskills):

 yes, just create a taxonomy for example fruits, then create a term in it
 eg Apple then attach 10 posts to term apple,
 Add this in your loop

 {{{
 echo get_the_term_list( $post->ID, 'fruits', '--', ' » ',"--" );
 }}}

 then open http://localhost/wp/?fruits=apple, offcourse you are going to
 print queries at somewhere in bottom or degub/save all queries

 for better claim just copy the get_the_term_list function to your theme
 function file and rename it like then call it and see if
 get_object_term_cache( $id, $taxonomy ); returns something or not ( a bit
 dirty method )

 i expanded it little bit

 {{{
 function get_the_term_list_2( $id = 0, $taxonomy, $before = '', $sep = '',
 $after = '' ) {
         //~ $terms = get_the_terms( $id, $taxonomy );
         //~ lets expand get_the_terms()


          global $post;
                 //~ print_r2($post);
                         $id = (int) $id;
                         if ( !$id )
                         {
                                 if ( !$post->id )
                                 return false;
                                 else
                                 $id = (int) $post->id;
                 }

                         $terms = get_object_term_cache( $id, $taxonomy );

                         // check here if you got something
                         // just print_r($terms);  // uncomment this

                         if ( false === $terms )
                         $terms = wp_get_object_terms( $id, $taxonomy );



         if ( is_wp_error( $terms ) )
                 return $terms;

         if ( empty( $terms ) )
                 return false;

         foreach ( $terms as $term ) {
                 $link = get_term_link( $term, $taxonomy );
                 if ( is_wp_error( $link ) )
                         return $link;
                 $term_links[] = '<a href="' . $link . '" rel="tag">' .
 $term->name . '</a>';
         }

         $term_links = apply_filters( "term_links-$taxonomy", $term_links
 );

         return $before . join( $sep, $term_links ) . $after;
 }


 }}}

 i hope it helps, the expanded function works great for homepage.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16253#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list