As in wordpress to filter posts by category?

Please help me to understand.
Inherited code which creates a new taxonomy. When you need to output to configure a filter for "categories" of posts.
When substituted into the array category => tagID, nothing is output.
Here is the code output of the post:
<?php $posts = get_posts( array(
 'numberposts' =--> 10, // same as posts_per_page
 'offset' => 0,
 'category' => 42,
 'orderby' => 'post_date',
 'order' => 'DESC',
 'include' => ",
 'exclude' => ",
 //'tag' => 'advert/required',
 'post_type' => 'advert_types',
 'post_mime_type' => ", // image, video, video/mp4
 'post_parent' => ",
 'post_status' => 'publish'
 ) ); 
 foreach($posts as $post){ setup_postdata($post); ?>
 <div class="advert-item">
 <a href="#" class="advert-header"><?php the_title() ?></a>
 <div class="detail-advert-info">(<?php the_time("H:i d.m.Y") ?>)</div>
 <div class="advert-detail" style="display: none;">
 <?php the_post_thumbnail(",'class=prewiev-anons')?>
 <?php the_content() ?>
</div>
</div>
 <?php }
 wp_reset_postdata(); ?>


Next, bring the code from functions.php:
add_action('init', 'add_advert_types');
add_advert_types function(){
 $labels = array(
 'name' => 'Announcement',
 'singular_name' => 'Announcement', // admin panel to Add->Function
 'add_new' => 'Add Declaration',
 'add_new_item' => 'Add announcement', // title tag <title>
 'edit_item' => 'Edit announcement',
 'new_item' => 'New ad',
 'all_items' => 'All listings',
 'view_item' => 'View advertisements',
 'search_items' => 'Search ad',
 'not_found' => 'Ads not found.',
 'not_found_in_trash' => ",
 'menu_name' => 'Private messages' // the menu link in the admin area
);

 $args = array(
 'labels' => $labels,
 'public' => true,
 'menu_position' => 5,
 'has_archive' => true,
 'supports' => array('title','editor', 'thumbnail','excerpt', 'custom-fields'),
 'taxonomy' => array('advert_category'),
 ); 

 register_post_type('advert_types', $args );
}
add_advert_taxonomies function(){
register_taxonomy('advert_category',
array('advert_types'),
array(
 'hierarchical' => true,
 /* true - type columns, false - for label, 
 defaults to false. */
 'labels' => array(
 /* labels needed to create the UI, you can
 do not write anything, then will be used
 labels by default */
 'name' => 'ad Categories',
 'singular_name' => 'Category declarations',
 'search_items' => 'Find by category',
 'popular_items' => 'Popular category',
 'all_items' => 'All catgorie ads',
 'parent_item' => null,
 'parent_item_colon' => null,
 'edit_item' => 'Edit category', 
 'update_item' => 'Update Category',
 'add_new_item' => 'Add new ad category',
 'new_item_name' => 'the name of the new category',
 'separate_items_with_commas' => 'Separate category with commas',
 'add_or_remove_items' => 'Add or remove category',
 'choose_from_most_used' => 'Choose from most used categories',
 'menu_name' => 'ad Categories'
),
 'public' => true, 
 /* anyone can use the taxonomy, or
 only admins, default is true */
 'show_in_nav_menus' => true,
 /* to add a page to menu creation */
 'show_ui' => true,
 /* add interface to create and edit */
 'show_tagcloud' => true,
 /* whether to allow the tag cloud for this taxonomy */
 'update_count_callback' => '_update_post_term_count',
 /* callback to update the counter $object_type */
 'query_var' => true,
 /* is it allowed to use query_var, you can also 
 to specify a string that will be used as 
 it defaults to the name of a taxonomy */
 'rewrite' => array(
 /* setting the URL permalinks */
 'slug' => 'advert', // label
 'hierarchical' => false, / / allow nesting

),
)
);

}
add_action( 'init', 'add_advert_taxonomies', 0 );</code></pre></title>
July 9th 19 at 14:01
1 answer
July 9th 19 at 14:03
Display using WP_Query and not break my head
wp-kama.ru/function/wp_query

Find more questions by tags WordPress