I’m sure this question is asked alot, but I cannot figure it out, since all the different ways to query posts are confusing me..
Here is my current code.
How can I tell the code to only get posts from category ID #22?
<?php
$querystr = "
SELECT post_id, AVG(meta_value) AS total, COUNT(post_id) as num_karakter
FROM sk_postmeta
WHERE meta_key = 'krit_karakter'
GROUP BY post_id
ORDER BY total DESC
LIMIT 5
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts) { ?>
<ul class="smartbar-items">
<?php foreach ($pageposts as $post):
setup_postdata($post); ?>
<li><a href="<?php echo get_permalink($post->post_id);?>"><img src="<?php bloginfo('url');?>/wp-content/files_mf/<?php echo get_post_meta($post->post_id, 'game_poster', true); ?>" width="80" height="110" alt="<?php echo get_the_title($post->post_id);?>" /> <br /><?php echo get_the_title($post->post_id);?></a></li>
<?php endforeach; ?>
</ul>
Thanks for all help!
I would do this in two pieces.
Add this into your functions.php file to grab custom fields globally:
}
Build your query as follows:
I can’t seem to get markdown to play nice, so here’s the code in Pastie http://pastie.org/1294594
You would need to join in the sk_term_relationships table.