Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widget( $args, $instance ) {
- // Widget output
- extract( $args );
- $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : null;
- $level = sanitize_text_field( $instance['level'] );
- /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
- $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
- // Get all the taxonomies to which this object belongs
- $type = get_post_type();
- $customPostTaxonomies = get_object_taxonomies( $type );
- if(count($customPostTaxonomies))
- {
- echo $before_widget;
- if ( $title ) {
- echo $args['before_title'] . $title . $args['after_title'];
- }
- foreach($customPostTaxonomies as $tax)
- {
- // Get all the categories in the current taxonomy
- $args = array(
- 'taxonomy' => $tax,
- );
- $myPostTaxonomies = get_categories ( $args );
- foreach($myPostTaxonomies as $myPostTax) {
- // Get all the posts in the current category
- ?>
- <<?php echo $level; ?>><?php echo $myPostTax->name; ?></<?php echo $level; ?>>
- <?php $categoryArgs = array(
- 'orderby' => 'post_date',
- 'order' => 'DESC',
- 'post_type' => $type,
- 'category' => $myPostTax->slug // seems not to be working
- );
- $postsArray = get_posts( $categoryArgs );
- if( count( $postsArray ) ) {
- ?> <ul>
- <?php
- foreach($postsArray as $myPost) {
- ?>
- <li><a href="<?php echo get_permalink( $myPost->post_title ); ?>"><?php echo $myPost->post_title; ?></a></li>
- <?php } ?>
- </ul>
- <?php }
- }
- }
- echo $after_title;
- }
- echo $after_widget;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement