开发者

How to find one categories all posts' all category? And again specific category form those categories.?

开发者 https://www.devze.com 2023-04-06 02:58 出处:网络
I have one category named City and Se开发者_如何学Ccond category Named Decease Inside City different cities will be there and inside Decease different decease will be there.

I have one category named City and Se开发者_如何学Ccond category Named Decease Inside City different cities will be there and inside Decease different decease will be there.

I will have posts having one city and more than one decease.

So what I want is when I click on One City I want to show all the decease belonging to this category.

So In detail with one city suppose 4 posts are there and all posts belongs to some decease So I need to find that how many posts are there having one category as this city. And then I need to find All the categories of all these posts and from that I need to find which categories parent category name is Decease. And then I need to show those categories.

How I should code this in wordpress in a nice manner? If some one has already spend some time on doing like this code then Kindly guide what will be good way to do this.


$deseace_cat_id = getCareTypeCategoryId(); 
    $careType=array();
    if(have_posts())
    {
        $cats = array();
        $cat_ids=array();                           

         while (have_posts()) : the_post();
            $post_categories = wp_get_post_categories( $post->ID );
            foreach($post_categories as $c){                
                $cat = get_category( $c );
                if(!in_array($c, $cat_ids) && $cat->category_parent==$deseace_cat_id)
                {
                    $cat_ids[]=$c;          
                    $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );                          
                }               
            }                                                           
            echo "<br>";
         endwhile;
         for($i=0;$i<count($cats);$i++)
         {
            ?>
            <a class="careTypeUrl" href="#" careSlug='<?php echo $cats[$i]['slug'];?>'><?php echo $cats[$i]['name'];?></a><br>
            <?php   
         }       
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号