get_posts() JOIN another table ?
-
My site use WooTheme and I want to display popular posts on Popular tab within WooTabs Widget as Most Read Posts in a week, not as Most Comment Count by default.
Here’s the default code of WooTabs’s Popular Tab:
if (!function_exists('woo_tabs_popular')) { function woo_tabs_popular( $posts = 5, $size = 35 ) { global $post; $popular = get_posts('caller_get_posts=1&orderby=comment_count&showposts='.$posts); foreach($popular as $post) : setup_postdata($post); ?> <li> <?php if ($size <> 0) woo_image('height='.$size.'&width='.$size.'&class=thumbnail&single=true'); ?> <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a> <span class="meta"><?php the_time( get_option( 'date_format' ) ); ?></span> <div class="fix"></div> </li> <?php endforeach; } }
I try to find a plugin to record post hits and I installed “Most Read in XX Days”.
This Plugin create a table named “most_read_hits”:
(ID, post_ID, hits)
and any post read count within a number of days will be recorded in to “hits” field.Now I want to use the “hits” field in “most_read_hits” to get and order some posts get from get_post() (Edit the code of “WooTabs Popular Posts” above.
I tried to edit
$popular = get_posts('caller_get_posts=1&orderby=comment_count&showposts='.$posts);
to
$popular = get_posts('caller_get_posts=1&join="JOIN $wpdb->most_read_hits ON $wpdb->posts.ID = $wpdb->most_read_hits.post_ID"&orderby=$wpdb->most_read_hits.hits&showposts='.$posts);
but it only lead to displaying latest posts.Anyone help me solve this?
Thank you!
- The topic ‘get_posts() JOIN another table ?’ is closed to new replies.