• Hello

    How can I exclude children categories?

    if( $form['name'] != 'search' ) {
            return $form;
        }
    
        $form['field'][] = array(
            "name" => "advert_category",
            "type" => "adverts_field_select",
    		'hierarchical' => false,
    		 'hide_empty'   => true,
            "order" => 20,
            "label" => __("", "adverts"),
            "max_choices" => 1,
            "options" => array(),
            "options_callback" => "adverts_taxonomies",
    		"empty_option_text" => "Kategória kiválasztása",
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "half" 
            )
        );
    
        return $form;
    }

    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    one options would be to get all top categories into an array

    
    $options = array();
    $terms = get_terms( array(
        'taxonomy' => 'advert_category',
        'hide_empty' => false,
        'parent' => 0,
    ) );
    foreach( $terms as $term ) {
        $options[] = array(
            "value" => $term->term_id,
            "text" => $term->name  
        );
    }
    

    and in your code set the options as

    
    ...
    "options" => $options,
    ...
    

    the options_callback line you can remove.

Viewing 1 replies (of 1 total)
  • The topic ‘Parent only category’ is closed to new replies.