Child Category Posts via Custom Query
-
Hello!
My morning was a nice one; found answers to a lot of questions regarding custom SQL queries in WordPress. (see thread) Now the archive template displays all posts sorted by a custom ‘year’ tag with working page navigation and stuff. (in action)
Still, when I display a parent category, the query finds nothing (see page). How do I modify my query to show posts of child categories? I tried to sort out this nice article by Kafkaesqi about parents and childs, but got confused.The code in use:
<?php
$pagelimit=6;
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$pagenum=($page-1)*$pagelimit;$pageposts = $wpdb->get_results("
SELECT * FROM $wpdb->posts, $wpdb->post2cat, $wpdb->postmeta
WHERE ID = $wpdb->postmeta.post_id
AND ID = $wpdb->post2cat.post_id
AND category_id = $cat
AND meta_key = 'year'
AND post_status = 'publish'
ORDER BY meta_value DESC
LIMIT $pagenum,$pagelimit
", OBJECT); ?>Thanks in advance for any hint!
- The topic ‘Child Category Posts via Custom Query’ is closed to new replies.