Potřeboval bych pomoct s podmínkou.. snažím se na stránce kategorie stránka s taxonomy.....udělat, že když nebude mít kategorie žádné subkategorie..tak to zobrazí rovnou příspěvky dané kategorie, jinak to má zobrazit subkategorie...z kterých se zase rozklikne na příspěvky.....

Potřeboval bych pomoct s tou podmínkou..else mi na to nereaguje..... předem díky za pomoc.

Zde je funkce:

Kód:
function ow_categories_with_subcategories_and_posts( $taxonomy, $post_type, $term_id ) {
    $taxonomy   = $taxonomy;
    $post_type  = $post_type;
    

     
   

      
      $this_category = get_category($taxonomy);
      if ( get_category_children( $this_category->cat_ID ) != "" ) {
      
      
            $subcategories = get_terms(
                array(
                    'taxonomy'   => $taxonomy,
                    'parent'     => $term_id, // <-- The parent is the current category
                    'orderby'    => 'term_id',
                    'hide_empty' => true
                )
            );
            ?>
              <ul class="row">
                <?php
                // Iterate through all subcategories to display each individual subcategory
                foreach ( $subcategories as $subcategory ) {

                    $subcat_name = $subcategory->name;
                    $subcat_id   = $subcategory->term_id;
                    $subcat_slug = $subcategory->slug;
                  
$obrazek_do_vypisu_pro_subkategorie = get_field( 'obrazek_do_vypisu_do_subkategorie', $subcategory->taxonomy . '_' .  $subcategory->term_id ); ?>

                  
                
        <li class="col-md-6 col-lg-4 col-xl-3">
          <a href="<?php echo get_category_link( $subcat_id  );  ?>" class="category-item">
            <div class="category-img">
          
            <?php if ( $obrazek_do_vypisu_pro_subkategorie ) { ?>
	<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="<?php echo $obrazek_do_vypisu_pro_subkategorie['sizes']['medium']; ?>" alt="<?php echo $obrazek_do_vypisu_pro_subkategorie['alt']; ?>" class="my-auto mx-auto img-fluid"  />
<?php } ?>  
              
              
                </div>
                
            <h3 class="h6"> <?php echo $subcat_name ; ?></h3>
            <span class="btn"><?php the_field( 'nazev_tlacitka_produkty',  'option' ); ?></span>
        </a>       
          </li>        
                   <?php


                   }
                ?>
                </ul>
                <?php   
              
            }else {
            
            
            
          ?>
    
                  <ul class="row">
                      <?php  
                    // Get all posts that belong to this specific subcategory
                    $posts = new WP_Query(
                        array(
                            'post_type'      => $post_type,
                            'posts_per_page' => -1, // <-- Show all posts
                            'hide_empty'     => true,
                            'orderby' => 'menu_order',
                             
                            'tax_query'      => array(
                                array(
                                
                                    'taxonomy' => $taxonomy,
                                    'terms'    => $term_id,  
                                    'field'    => 'id'
                                )
                            )
                        )
                    );

                    // If there are posts available within this subcategory
                    if ( $posts->have_posts() ):
                        ?>
                       
                            <?php

                            // As long as there are posts to show
                            while ( $posts->have_posts() ): $posts->the_post();

                                //Show the title of each post with the Post ID
                                ?>
                                
    <li class="col-md-6 col-lg-4 col-xl-3">
          <a href="<?php the_permalink();?>" class="category-item">
            <div class="category-img">
            
         <?php $obrazek_produktu_do_vypisu = get_field( 'obrazek_do_detailu' ); ?>
<?php if ( $obrazek_produktu_do_vypisu ) { ?>


              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="<?php echo $obrazek_produktu_do_vypisu['sizes']['medium']; ?>" alt="<?php echo $obrazek_produktu_do_vypisu['alt']; ?>" class="my-auto mx-auto img-fluid" />
          <?php } ?>   
          
            </div>
            <h3 class="h6"><?php the_title();?></h3>
            <span class="btn"><?php the_field( 'nazev_tlacitka_produkty',  'option' ); ?></span>
        </a>
   </li>
                                
                                
                              
                                <?php

                            endwhile;
                            ?>
                        
                        <?php
                    else:
                        echo 'No posts found';
                    endif;
                    ?>
                    
                    </ul>
                    <?php
                    wp_reset_query();      
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            }
          
            
           $this_category = get_queried_object(); 
         if(0 != $this_category->parent) {    
    // do required actions     
    
    ?>
    
                  <ul class="row">
                      <?php  
                    // Get all posts that belong to this specific subcategory
                    $posts = new WP_Query(
                        array(
                            'post_type'      => $post_type,
                            'posts_per_page' => -1, // <-- Show all posts
                            'hide_empty'     => true,
                            'orderby' => 'menu_order',
                             
                            'tax_query'      => array(
                                array(
                                
                                    'taxonomy' => $taxonomy,
                                    'terms'    => $term_id,  
                                    'field'    => 'id'
                                )
                            )
                        )
                    );

                    // If there are posts available within this subcategory
                    if ( $posts->have_posts() ):
                        ?>
                       
                            <?php

                            // As long as there are posts to show
                            while ( $posts->have_posts() ): $posts->the_post();

                                //Show the title of each post with the Post ID
                                ?>
                                
    <li class="col-md-6 col-lg-4 col-xl-3">
          <a href="<?php the_permalink();?>" class="category-item">
            <div class="category-img">
            
         <?php $obrazek_produktu_do_vypisu = get_field( 'obrazek_do_detailu' ); ?>
<?php if ( $obrazek_produktu_do_vypisu ) { ?>


              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="<?php echo $obrazek_produktu_do_vypisu['sizes']['medium']; ?>" alt="<?php echo $obrazek_produktu_do_vypisu['alt']; ?>" class="my-auto mx-auto img-fluid" />
          <?php } ?>   
          
            </div>
            <h3 class="h6"><?php the_title();?></h3>
            <span class="btn"><?php the_field( 'nazev_tlacitka_produkty',  'option' ); ?></span>
        </a>
   </li>
                                
                                
                              
                                <?php

                            endwhile;
                            ?>
                        
                        <?php
                    else:
                        echo 'No posts found';
                    endif;
                    ?>
                    
                    </ul>
                    <?php
                    wp_reset_query();
    }          
  
}


---------- Příspěvek doplněn 11.09.2019 v 18:09 ----------

Upraveno takto, ale opět nic.. zobrazí se jenom subkategorie, nebo jenom příspěvky....podle toho co dám do podmínky.....jestli rovno nebo nerovno...

Kód:
function ow_categories_with_subcategories_and_posts( $taxonomy, $post_type, $term_id ) {
    $taxonomy   = $taxonomy;
    $post_type  = $post_type;
    

     
   

        $this_category = get_queried_object(); 
         if(0 == $this_category->parent) {  
  
      
      
            $subcategories = get_terms(
                array(
                    'taxonomy'   => $taxonomy,
                    'parent'     => $term_id, // <-- The parent is the current category
                    'orderby'    => 'term_id',
                    'hide_empty' => true
                )
            );
            ?>
              <ul class="row">
                <?php
                // Iterate through all subcategories to display each individual subcategory
                foreach ( $subcategories as $subcategory ) {

                    $subcat_name = $subcategory->name;
                    $subcat_id   = $subcategory->term_id;
                    $subcat_slug = $subcategory->slug;
                  
$obrazek_do_vypisu_pro_subkategorie = get_field( 'obrazek_do_vypisu_do_subkategorie', $subcategory->taxonomy . '_' .  $subcategory->term_id ); ?>

                  
                
        <li class="col-md-6 col-lg-4 col-xl-3">
          <a href="<?php echo get_category_link( $subcat_id  );  ?>" class="category-item">
            <div class="category-img">
          
            <?php if ( $obrazek_do_vypisu_pro_subkategorie ) { ?>
	<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="<?php echo $obrazek_do_vypisu_pro_subkategorie['sizes']['medium']; ?>" alt="<?php echo $obrazek_do_vypisu_pro_subkategorie['alt']; ?>" class="my-auto mx-auto img-fluid"  />
<?php } ?>  
              
              
                </div>
                
            <h3 class="h6"> <?php echo $subcat_name ; ?></h3>
            <span class="btn"><?php the_field( 'nazev_tlacitka_produkty',  'option' ); ?></span>
        </a>       
          </li>        
                   <?php


                   }
                ?>
                </ul>
                <?php   
              
  
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
       
          
            
         }else { 
    // do required actions     
    
    ?>
    
                  <ul class="row">
                      <?php  
                    // Get all posts that belong to this specific subcategory
                    $posts = new WP_Query(
                        array(
                            'post_type'      => $post_type,
                            'posts_per_page' => -1, // <-- Show all posts
                            'hide_empty'     => true,
                            'orderby' => 'menu_order',
                             
                            'tax_query'      => array(
                                array(
                                
                                    'taxonomy' => $taxonomy,
                                    'terms'    => $term_id,  
                                    'field'    => 'id'
                                )
                            )
                        )
                    );

                    // If there are posts available within this subcategory
                    if ( $posts->have_posts() ):
                        ?>
                       
                            <?php

                            // As long as there are posts to show
                            while ( $posts->have_posts() ): $posts->the_post();

                                //Show the title of each post with the Post ID
                                ?>
                                
    <li class="col-md-6 col-lg-4 col-xl-3">
          <a href="<?php the_permalink();?>" class="category-item">
            <div class="category-img">
            
         <?php $obrazek_produktu_do_vypisu = get_field( 'obrazek_do_detailu' ); ?>
<?php if ( $obrazek_produktu_do_vypisu ) { ?>


              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="<?php echo $obrazek_produktu_do_vypisu['sizes']['medium']; ?>" alt="<?php echo $obrazek_produktu_do_vypisu['alt']; ?>" class="my-auto mx-auto img-fluid" />
          <?php } ?>   
          
            </div>
            <h3 class="h6"><?php the_title();?></h3>
            <span class="btn"><?php the_field( 'nazev_tlacitka_produkty',  'option' ); ?></span>
        </a>
   </li>
                                
                                
                              
                                <?php

                            endwhile;
                            ?>
                        
                        <?php
                    else:
                        echo 'No posts found';
                    endif;
                    ?>
                    
                    </ul>
                    <?php
                    wp_reset_query();
    }          
  
}


---------- Příspěvek doplněn 11.09.2019 v 19:00 ----------

Tak jsem na to přišel, tohle je řešení...

Kód:
global $wp_query;
$term = $wp_query->get_queried_object();  
$children = get_terms( $term->taxonomy, array(
'parent'    => $term->term_id,
'hide_empty' => false
) ); 
     
     
     
     
     
   
     
       
         if($children){  

}else{


}