0

I am displaying the area names using taxonomy in array format , each taxonomy have different area names and posts .When i click the area name it should pull out the all the posts from the all taxonomies , but my problem is area names are duplicating so i just want hide that duplicate area names .Can any one guide me to solve this .

Here is my Code :

<div id="footer">
<h1>Area Names </h1>
<?php

            $taxonomyArray = array("health_area","schools_area","office_area","salonsandsaps_area");

            for($Inc=0;$Inc<count($taxonomyArray);$Inc++){

                $orderby      = 'name';
                $show_count   = 0;      // 1 for yes, 0 for no
                $pad_counts   = 0;      // 1 for yes, 0 for no
                $hierarchical = 1;      // 1 for yes, 0 for no
                $title        = '';
                $empty        = 0;

                $args = array(
                    'taxonomy'     => $taxonomyArray[$Inc],
                    'orderby'      => $orderby,
                    'show_count'   => $show_count,
                    'pad_counts'   => $pad_counts,
                    'hierarchical' => $hierarchical,
                    'title_li'     => $title,
                    'hide_empty'   => $empty
                    );

                wp_list_categories( $args ); 

            }
        ?>
    </ul>

    </div>

Here is Screenshot of result

enter image description here

Thanks in Advance .

Screenshot of result after updating code :

enter image description here

0

I did not test the code. But this should be work.

<div id="footer">
<h1>Area Names </h1>
<?php

            $taxonomyArray = array("health_area","schools_area","office_area","salonsandsaps_area");

            $temp_array=array();

            for($Inc=0;$Inc<count($taxonomyArray);$Inc++){              


                $orderby      = 'name';
                $show_count   = 0;      // 1 for yes, 0 for no
                $pad_counts   = 0;      // 1 for yes, 0 for no
                $hierarchical = 1;      // 1 for yes, 0 for no
                $title        = '';
                $empty        = 0;

                if($Inc!=0)
                {
                    $temp_array=array_merge($temp_array,get_categories($args));
                }

                $args = array(
                    'taxonomy'     => $taxonomyArray[$Inc],
                    'orderby'      => $orderby,
                    'show_count'   => $show_count,
                    'pad_counts'   => $pad_counts,
                    'hierarchical' => $hierarchical,
                    'title_li'     => $title,
                    'hide_empty'   => $empty,
                    'exclude'      =>$temp_array
                    );

                wp_list_categories( $args ); 

            }
        ?>
    </ul>

    </div>
  • @Renuka , I tried this but it doesn't work – user2003956 Nov 9 '16 at 8:39
  • @user2003956 After array_merge($temp_array,get_categories($args)); part use print_r($temp_array);. So you can find that whether temp_array fill as we expected. – Ranuka Nov 9 '16 at 8:43
  • @Renuka , I did that , in the result some places it shows like this "Array () Array ()" and still the duplicate area names are displaying . – user2003956 Nov 9 '16 at 9:14
  • @user2003956 I have done a mistake in one line. I edited the my code. Now try it. Even it won't work again use print_r($temp_array); let me the result. – Ranuka Nov 9 '16 at 9:34
  • as you said i updated the code and it doesn't work , then i use print the result not coming properly, for reference in my question i have updated my latest screenshot please check it . – user2003956 Nov 9 '16 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.