WordPress | WP_Query | Get latest port from category and sub-categories -


i have write theme wordpress , have latest posts posted in category , it's sub-categories displayed on top of other post.

an example. lets have following categories:

cat 1     cat 1 - 1     cat 1 - 2         cat 1 - 2 - 1 

and create following posts :

post #5   |   cat 1 - 2       | date 2013 post #4   |   cat 1 - 1       | date 2012 post #3   |   cat 1 - 2       | date 2011 post #2   |   cat 1           | date 2010 post #1   |   cat 1 - 1 - 2   | date 2009 

in front end, when navigate cat 1 not latest post post #5 belong cat 1 - 2 sub category of cat 1, instead getting post #2.

currently using code :

$categoryid         =   get_query_var('cat');  $args   =   array(     'post_type'         =>  'post',     'posts_per_page'    =>  1,     'category__in'      =>  array($categoryid),     'post_status'       =>  'publish' );  $eipost =   new wp_query($args); 

the problem code return latest post top level category , not sub categories. how can modify code, in order retrieve latest posts sub-categories , top category ?

is there solution problem ?

'category__in' displays posts category, not children categories.

try using 'cat' => $categoryid insted. $args be:

$args   =   array( 'post_type'         =>  'post', 'posts_per_page'    =>  1, 'cat'      =>  $categoryid, 'post_status'       =>  'publish' ); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -