V
V
Vyacheslav Belyaev2015-08-27 11:09:09
CMS
Vyacheslav Belyaev, 2015-08-27 11:09:09

How to display internal headings and posts?

There is a heading in which other headings and posts are nested. Other posts are attached to child headings.
How to list internal categories and posts (without posts of child categories)

$term_id = 28; //Динамическая категория получаемая от открытой категории

      $categories_sub = get_categories(array(
                    'child_of' => 0,
                    'parent' => $term_id,
                    'orderby' => 'name',
                    'order' => 'ASC',
                    'hide_empty' => 0,
                    'hierarchical' => 1,
                    'number' => 0,
                    'taxonomy' => 'category',
                    'pad_counts' => false
                ));


                $posts_sub = get_posts(array(
                    'offset' => 0,
                    'category' => $term_id,
                    'orderby' => 'post_date',
                    'order' => 'DESC',
                    'meta_value' => '',
                    'post_type' => 'post',
                    'post_status' => 'publish'
                ));
 $data_list = array_merge($categories_sub, $posts_sub);

Here is my code. The list of categories is normal, but the list of posts is displayed with the posts of child categories.
There is also some strange "anomaly". When trying to output var_dump(get_the_category()); before the beginning of the whole code, one of the child categories is displayed. And the_title() displays the title of the first post of the child category. How can I reset it or what else can I do with it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question