PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

exclude categories from category post-field and include all new categories

  1. Hi I have a form where I want to include a drop-down menu to post a category. I want the drop-down to be populated will all categories - so new ones that get created. However there are 4 old categories that I would like to exclude from the list. Is this possible? I have also tried to simply remove the list items using nth-child with jquery - however this won't work because the drop-down gets sorted by alphabetical order and when a new category is added that with mess with the order. Does anyone have any thoughts on how I can accomplish this?

    Thanks!

    Posted 8 years ago on Wednesday September 26, 2012 | Permalink
  2. You might have to use dynamic population to exclude the old categories which you do not want shown in the drop down. Here is an explanation of how to dynamically populate a drop down with the gform_pre_render filter.

    http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields

    In the code, http://pastie.org/2105544 on line 14, you will be retrieving categories, not posts, and you will be excluding some categories. That line, for your application, might look like this:

    [php]
    $args = array(
    	'type'                     => 'post',
    	'orderby'                  => 'name',
    	'order'                    => 'ASC',
    	// show only children of parent category 3
    	'parent'                    => '3',
    	// exclude categories 4, 7, 12 and 25
    	'exclude'                  => '4,7,12,25',
    	'taxonomy'                 => 'category');
    $categories = get_categories($args);

    Then, loop through the categories, not the posts.

    Here is the documentation for get_categories:
    http://codex.wordpress.org/Function_Reference/get_categories

    Posted 8 years ago on Monday October 1, 2012 | Permalink
  3. Thanks for the reply! I did try some of the dynamic population tutorials on this site but it seems the problem may be that it is a post field to a category - and they didn't seem to work. I will try the above recommendations though and see if I can get it to work.

    Thanks I will keep you updated!

    Posted 8 years ago on Monday October 15, 2012 | Permalink
  4. Please let us know if you need more help.

    Posted 8 years ago on Monday October 15, 2012 | Permalink

This topic has been resolved and has been closed to new replies.