Opened 12 years ago
Closed 12 years ago
#16253 closed defect (bug) (invalid)
Object term cache not working for taxonomy query page - resulting 200 queries for 10 posts
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 3.0.4 |
Component: | Cache API | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
This problem is very similar to #12989
but now it happen when you query a taxonomy,
$terms = get_object_term_cache( $id, $taxonomy ); in get_the_terms() Return nothing $link = get_term_link( $term, $taxonomy ); in get_the_term_list() also increase queries
i am not that lucky with wordpress(Coding) to provide a patch but it took me lots of time to figure out why its happening.
Change History (11)
#3
@
12 years ago
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. now if you increase the terms attached to post it will increase queries.
#7
@
12 years ago
I can't seem to reproduce.
Here is the code I'm using, on a clean install of Twentyten:
<?php add_action('init', function() { register_taxonomy('color', 'post', array('label' => 'Color')); }); add_action('the_post', function( $post ) { print_r( get_object_term_cache( $post->ID, 'color' ) ); echo the_terms( $post->ID, 'color' ); });
When going to ?color=green
, the cache is pre-filled by WP_Query.
#9
@
12 years ago
- Resolution set to fixed
- Status changed from new to closed
i just completed testing with build 3.1-RC2-17315, and i found that there is no bug is latest build. taxonomy page comes in 20 queries (60 above in 3.0.4)
so closing the ticket.
Could you provide some steps to reproduce?