# wpdirectorykit/1.1.0/application/views/search_fields/CATEGORY.php

WP Directory Kit, version 1.1.0. 56 lines.

- Page: https://pluginprobe.com/plugins/wpdirectorykit/1.1.0/code/application/views/search_fields/CATEGORY.php
- Raw: https://pluginprobe.com/plugins/wpdirectorykit/1.1.0/raw/application/views/search_fields/CATEGORY.php
- Modified: 2022-11-24T13:50:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpdirectorykit/1.1.0/code/application/views/search_fields/CATEGORY.php#L10-L20`.

```php
<?php
/**
 * The template for Search field CATEGORY.
 *
 * This is the template that field layout for search form
 *
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
?>
<?php
$field_key = 'search_'.wmvc_show_data('idfield',$field_data);
$field_attr_id = 'wdk_search_'.wmvc_show_data('idfield', $field_data);
$placeholder = wmvc_show_data('field_label', $field_data);
$field_value = '';

$filter_ids = array();
if(isset($predefinedfields_query) && !empty($predefinedfields_query[$field_key])) {
    $field_value = intval($predefinedfields_query[$field_key]);
}

if(isset($predefinedfields_query) && !empty($predefinedfields_query['custom_category_root'])) {
    $custom_field_value = intval($predefinedfields_query['custom_category_root']);
    global $Winter_MVC_WDK;
    $Winter_MVC_WDK->load_helper('listing');
    $Winter_MVC_WDK->model('category_m');
    $location = $Winter_MVC_WDK->category_m->get($custom_field_value, TRUE); 

    /* if root search childs */
    if(empty(wmvc_show_data('parent_id', $location, false, TRUE, TRUE))) {
        $filter_ids = $Winter_MVC_WDK->category_m->get_all_childs($custom_field_value); 
        if(!empty($filter_ids)) {
            $filter_ids[] = $custom_field_value;

            if(in_array($field_value, $filter_ids) === FALSE) {
                $field_value = $custom_field_value;
            }
        }
    }
}    

if(isset($_GET[$field_key])) {
    $field_value = sanitize_text_field($_GET[$field_key]);
}

wdk_search_fields_toggle();
?>

<div class="wdk-field wdk-col <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>">
    <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
    <div class="wdk-field-group">
        <?php echo wdk_treefield_option ('search_category', 'category_m', $field_value, 'category_title', '', __('All Categories', 'wpdirectorykit'), $filter_ids);?>
    </div>
</div>
```
