I get posts for categories by ID so

$my_post = query_posts('cat='.$cat); // Где $cat это ID нужной категории 

But all posts are displayed, including child categories.
Tell me how to display posts of a certain category, excluding subsidiaries?

    2 answers 2

    Important: do not use query_posts ()

    query_posts() intended for WordPress itself and should be used to modify the main WordPress Cycle, if you need to create another cycle, use get_posts() or WP_Query . Since version 3.0, these functions can take all the same parameters as query_posts() .

    I suppose you need to get something like this

     $myPosts = get_posts(array( 'category' => $cat, 'category_name' => $cat_name // Не уверен, что это необходимо )); 

    Where

    category (string / number) - From which categories to display entries. Specify the category ID from which you want to get the posts or specify -3 instead of 3 if you want to get all the entries, except for the entries from category 3 (exclude category). You can specify multiple IDs separated by commas ("3,5,12" or "-3, -5, -12"). The array can not be transferred.
    Default: No

    category_name (string) - posts only from this category (indicate the name or alternative name (slug) of the category).
    Default: No

    More details can be found here .

      Use the category__in parameter instead of cat :

       $my_post = query_posts('category__in='.$cat);