Skip to main content

How to displydisplay posts under a specific subcategory of a given category

Source Link
Musta
  • 11
  • 2

How to disply posts under a specific subcategory of a given category

after a long search online I have decided to post my problem here in the hope of getting a solution to this issue. Well, I have a custom post with various categories (novels, books, magazines etc..) and each of these categories have many subcategories (2002, 2004, 2005, 2006 etc) the year of publication. Basically what I need is to show a filtering menu based only on the relevent subcategories of the selected category. And when the user clicks on a subcategory menu item he will be able to get all the posts under that specific category.

this is what I have done so far, but I could no find out how filter by subcategory while in a given category.

        if (isset($_GET['cat'])){
    $subcat = $_GET['cat'];
    query_posts( 'posts_per_page=10&paged='.$paged.'&post_type=publication&publication_category='.$maincat.**'&category__in='**.$subcat );
        }else{
    query_posts( 'posts_per_page=10&paged='.$paged.'&post_type=publication&publication_category='.$maincat );   
    }

I be so thankful to anyone who could give me a bit of his time to solve this problem.