wp_list_categories exclude all child categories

Discussion in 'WordPress' started by Matt18, Jul 23, 2011.

  1. #1
    Hi

    I would like to exclude from my menus all child categories from a particular parent.

    Parent category has ID 111. I do not want to enter all ID of all child categories, so I would somehow like to set exclude all child of 111.

    Can you maybe help me please?

    Thank you in advance!

    Edit: I think I might be in the right way. This is what I have so far:

    <?php 
    	 		echo " <ul id='nav'>";	
    			$ex_catIdArr = get_categories('child_of=111');
    			$catIdArr = array();
    			foreach($ex_catIdArr as $ex_catIdArrObj)
    			{
    				$catIdArr[] = $ex_catIdArrObj->term_id;
    			}
    			$includeCats = implode(',',$catIdArr);
    			wp_list_categories('orderby=order&title_li=&exclude='.$includeCats);
    		?>
    Code (markup):

    The only problem is, that get_categories('child_of=111') does not get me all childs... Code works if I set include=111, but it the excluded only 111 in the list.
     
    Last edited: Jul 23, 2011
    Matt18, Jul 23, 2011 IP
  2. Aman Arora

    Aman Arora Active Member

    Messages:
    100
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #2
    I tried to find something for you, but my bad luch didn't got anything. I guess you will have to put all id's manually :(
     
    Aman Arora, Jul 23, 2011 IP
  3. mohsince

    mohsince Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $categories= get_categories('child_of=10');

    works fine for me ? can u please check issue is in your lop
     
    mohsince, Jul 24, 2011 IP
  4. Matt18

    Matt18 Guest

    Messages:
    591
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is not happening inside loop. I managed to solve the problem.

    the code in my first post actually works! The problem was, that I was importing categories manually and somehow connection from wp to database was not "refreshed" or something. So all I had to do it add one category through wp-admin, then deleted it as I didn't need it, and code above worked...
     
    Matt18, Jul 25, 2011 IP