Custom select query – sort by meta value within category
Hi, I’ve tried all sorts of ways to make this work, and have investigated options in http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query and all over the forum, but am failing.
What I’m after is when a user clicks on a category in the sidebar, they are taken to category.php which displays posts only in that category and then sorted by meta value. I’ve got the meta_value ASC bit working, but currently category.php shows all posts in all categories.
this is my code so far – can anyone tell me how I also include the info that returns only the posts included in the category chosen in the sidebar.
$querystr = “
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = ‘surname’
AND wposts.post_type = ‘post’
ORDER BY wpostmeta.meta_value ASC
Your help would be much appreciated…
- The topic ‘Custom select query – sort by meta value within category’ is closed to new replies.