SQL order by a row from another table
-
Hi, I’m trying to display a list of posts that is ordered by a count of how many people liked it, that count is stored in another table.
The table is called likes_count
https://i.imgur.com/82mvH.png
page ID and like count.I’m using this piece of code:
<?php $query_sql = " SELECT * FROM $wpdb->posts WHERE post_type = 'post' ORDER BY like_count DESC "; $query_result = $wpdb->get_results( $wpdb->prepare ($query_sql, OBJECT)); ?> <?php if ($query_result): ?> <?php foreach ($query_result as $post): ?> <?php setup_postdata($post); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <?php endforeach; ?> <?php else : ?> <p>Not found</p> <?php endif; ?>
for the sql query and to pull and display the articles so I can use template tags, I just cant work out how to ORDER BY ‘a row from another table’.
Thanks.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘SQL order by a row from another table’ is closed to new replies.