Zeige nur Begriffe aus der übergeordneten Kategorie

Ich habe einen Code, der zufällige Beiträge aus den gleichen Kategorien auf der Kategorie-Seite zeigt. Ich benutze Kinder- und Elternkategorien und ich möchte nur solche Beiträge aus derselben Kindkategorie oder derselben Elternkategorie zeigen. Im Moment zeigt der Code beide (Beiträge von Eltern- und Kind-Kategorie) auf der Kind-Kategorie-Seite an. Ich habe keine Lösung gefunden, um dieses Problem zu beheben. Ich habe es versucht

get_terms( array('parent' => 0 ) ); 

und auch andere Wege. kann mir jemand helfen?

 /*recent posts*/ function my_posts_from_category( $atts, $content = null ) { extract(shortcode_atts(array( 'count' => 5, 'verbose' => '0' // '1' outputs some debug info ), $atts)); $verbose = ( $verbose !== '0' ); $content = ''; $current_categories = array(); global $post; if ( !empty( $post ) ) { // get all categories of current post $terms = get_the_terms( $post->ID, 'category', 'orderby=count&hide_empty=0&parent=0'); if ( $terms && !is_wp_error( $terms ) ) { foreach( $terms as $term ) { /*if ($_term->parent == 0) //check for parent terms only*/ $current_categories[] = $term; } } } else { if ( $verbose ) $content = 'posts_from_category: no $post...'; } foreach ( $current_categories as $category ) { // get all tags of current post $found_terms = array(); $terms = get_the_terms( $post->ID, 'post_tag' ); if ( !is_wp_error( $terms ) && !empty( $terms ) ) { foreach ( $terms as $term ) { $found_terms[] = $term->term_id; } } // list of ids to exclude, first entry: current post $my_exclude_ids = array( $post->ID ); // ids of related posts of current post $my_related_post_ids = array(); foreach ( $found_terms as $found_term ) { // get one post with found tag ordered by random $args = array( 'posts_per_page' => 1, 'orderby' => 'rand', 'tax_query' => array( array( 'taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $found_term ) ), 'suppress_filters' => false, 'fields' => 'ids', 'post__not_in' => $my_exclude_ids // exclude already found posts ); $my_related_post_id = get_posts( $args ); // actually max. 1 post if ( !empty( $my_related_post_id ) ) { $my_related_post_ids = array_merge( $my_related_post_ids, $my_related_post_id ); $my_exclude_ids = array_merge( $my_exclude_ids, $my_related_post_id ); } } // get all post ids of current category ordered by date $args = array( 'posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'id', 'terms' => $category->term_id ) ), 'suppress_filters' => false, 'fields' => 'ids', 'post__not_in' => $my_exclude_ids // exclude current post ); $my_post_ids = get_posts( $args ); // result could be empty if all found were also related before // combine results $my_post_ids = array_merge( $my_post_ids, $my_related_post_ids ); // mix results in random order, todo, array_splice(len=0)? shuffle( $my_post_ids ); $posts_lis = array(); foreach ( $my_post_ids as $my_post_id ) { // add a post $posts_lis[ 'id_' . $my_post_id ] = '
  • ' . get_the_title($my_post_id ) . ' (' . get_the_date( get_option( 'date_format' ), $my_post_id ) . ')
  • '; // limit output if ( count( $posts_lis ) >= $count ) { break; } } // build html container $content .= '
    slug . '">'; $content .= '

    Bei Lesern der Kategorie slug, 'category' ) ) . '">' . $category->name . ' ebenfalls beliebt:

    '; $content .= '
      '; $content .= implode( $posts_lis ); $content .= '
    '; $content .= '
    '; } return $content; }

    Solutions Collecting From Web of "Zeige nur Begriffe aus der übergeordneten Kategorie"