0

I have categories and sub -categories with same name.. but I want to show only the categories which is on the top level and not in the sub categories

$qry=query_posts( array( 
    'post_status' => 'publish',
    'post_type' => 'custom_post',
    'author' => '12;,
    'showposts' => 9,
    'tax_query' => array(
    array(
        'taxonomy' => 'custom_cat,
        'terms' => 10,
        'field' => 'id'
    ) ),
    'orderby' => 'id',
    'order' => 'DESC'
));

my categories will be like

test
  --news
  --magzine
news

2 Answers 2

1

See Taxonomy Parameters documentation - there is include_children parameter, which you can set to false in your taxonomy query.

0

try this

while($qry->have_posts()){
 $qry->the_post;
 foreach((get_the_category()) as $category) {
   //check if category have parent or not
   if ($category->category_parent == 0) {
   //your code goes here for post
 }
}

important Link:

  1. get_the_category()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.