Skip to content

Instantly share code, notes, and snippets.

@fritids
Forked from jmabbas/function.php
Created August 8, 2020 06:36
Show Gist options
  • Save fritids/ac341c27034b60d0da0f9fdaa6b29234 to your computer and use it in GitHub Desktop.
Save fritids/ac341c27034b60d0da0f9fdaa6b29234 to your computer and use it in GitHub Desktop.
Front - job location header
if ( ! function_exists( 'front_job_header_search_form' ) ) {
function front_job_header_search_form( $args = array() ) {
$defaults = apply_filters( 'front_job_header_search_form_default_args', array(
'keywords_title_text' => esc_html__( 'what', 'front' ),
'keywords_subtitle_text' => esc_html__( 'job title, keywords, or company', 'front' ),
'keywords_placeholder_text' => esc_html__( 'Keyword or title', 'front' ),
'location_title_text' => esc_html__( 'where', 'front' ),
'location_subtitle_text' => esc_html__( 'city, state, or zip code', 'front' ),
'location_placeholder_text' => esc_html__( 'City, state, or zip', 'front' ),
'category_title_text' => esc_html__( 'which', 'front' ),
'category_subtitle_text' => esc_html__( 'department, industry, or specialism', 'front' ),
'category_placeholder_text' => esc_html__( 'All Category', 'front' ),
'search_button_text' => esc_html__( 'Find Jobs', 'front' ),
'background_color' => 'bg-light',
'current_page_url' => '',
'enable_container' => true,
) );
$args = wp_parse_args( $args, $defaults );
extract( $args );
$current_page_url = ! empty($current_page_url) ? $current_page_url : Front_WPJM::get_current_page_url();
$current_page_query_args = Front_WPJM::get_current_page_query_args();
?>
<div class="job-filters<?php echo esc_attr( !empty( $background_color ) ? ' ' . $background_color : '' ); ?>">
<div class="<?php echo esc_attr( !empty( $enable_container ) ? 'container space-1' : '' ); ?>">
<!-- Search Jobs Form -->
<form class="job_filters_form" action="<?php echo esc_attr( $current_page_url ); ?>">
<?php do_action( 'job_manager_job_header_search_block_start' ); ?>
<div class="search_jobs row mb-2">
<?php do_action( 'job_manager_job_header_search_block_search_jobs_start' ); ?>
<div class="search_keywords col-lg-5 mb-4 mb-lg-0">
<!-- Input -->
<label for="search_keywords" class="d-block">
<span class="h4 d-block text-dark font-weight-semi-bold mb-0"><?php echo esc_html( $args['keywords_title_text'] ) ?></span>
<small class="d-block text-secondary">
<?php echo esc_html( $args['keywords_subtitle_text'] ) ?>
</small>
</label>
<div class="js-focus-state">
<div class="input-group">
<input type="text" name="search_keywords" id="search_keywords" class="form-control" placeholder="<?php echo esc_attr( $args['keywords_placeholder_text'] ) ?>" aria-label="<?php echo esc_attr( $args['keywords_placeholder_text'] ) ?>" aria-describedby="keywordInputAddon" value="<?php echo get_search_query(); ?>" />
<div class="input-group-append">
<span class="input-group-text">
<span class="fas fa-search" id="keywordInputAddon"></span>
</span>
</div>
</div>
</div>
<!-- End Input -->
</div>
<div class="search_location col-lg-5 mb-4 mb-lg-0">
<!-- Input -->
<label for="search_location" class="d-block">
<span class="h4 d-block text-dark font-weight-semi-bold mb-0"><?php echo esc_html( $args['location_title_text'] ) ?></span>
<small class="d-block text-secondary">
<?php echo esc_html( $args['location_subtitle_text'] ) ?>
</small>
</label>
<div class="js-focus-state">
<?php if ( taxonomy_exists( 'job_listing_region' ) && get_option( 'job_manager_regions_filter' ) ) : ?>
<?php wp_dropdown_categories( array('taxonomy' => 'job_listing_region', 'show_option_all' => ' Select Region','hierarchical' => 1, 'name' => 'filter_job_listing_region','id' => 'filter_job_listing_region','class' => 'jobhunt-job-region-select','value_field' => 'term_id','orderby' => 'name', 'selected' => isset( $_GET['filter_job_listing_region'] ) ? front_clean( wp_unslash( $_GET['filter_job_listing_region'] ) ) : '' ) ); ?>
<?php else : ?>
<div class="input-group">
<input type="text" name="search_location" id="search_location" class="form-control" placeholder="<?php echo esc_attr( $args['location_placeholder_text'] ) ?>" aria-label="<?php echo esc_attr( $args['location_placeholder_text'] ) ?>" aria-describedby="locationInputAddon" value="<?php echo esc_attr( isset( $_GET['search_location'] ) ? front_clean( wp_unslash( $_GET['search_location'] ) ) : '' ); ?>" />
<div class="input-group-append">
<span class="input-group-text">
<span class="fas fa-map-marker-alt" id="locationInputAddon"></span>
</span>
</div>
</div>
<?php endif; ?>
</div>
<!-- End Input -->
</div>
<div class="search_category d-none col-lg-3 mb-4 mb-lg-0">
<!-- Input -->
<label for="search_category" class="d-block">
<span class="h4 d-block text-dark font-weight-semi-bold mb-0"><?php echo esc_html( $args['category_title_text'] ) ?></span>
<small class="d-block text-secondary">
<?php echo esc_html( $args['category_subtitle_text'] ) ?>
</small>
</label>
<div class="js-focus-state">
<select id="search_category" name="search_category">
<option value=""><?php echo esc_html( $args['category_placeholder_text'] ); ?></option>
<?php foreach ( get_job_listing_categories() as $cat ) : ?>
<option value="<?php echo esc_attr( $cat->term_id ); ?>" <?php echo esc_attr( isset( $_GET['search_category'] ) && front_clean( wp_unslash( $_GET['search_category'] ) ) == $cat->term_id ? 'selected' : ''); ?>><?php echo esc_html( $cat->name ); ?></option>
<?php endforeach; ?>
</select>
</div>
<!-- End Input -->
</div>
<div class="search_submit col-lg-2 align-self-lg-end">
<button type="submit" class="btn btn-block btn-primary transition-3d-hover">
<?php echo esc_html( $search_button_text ); ?>
</button>
</div>
<input type="hidden" name="paged" value="1" />
<?php
if( is_array( $current_page_query_args ) && !empty( $current_page_query_args ) ) :
foreach ( $current_page_query_args as $key => $current_page_query_arg ) :
if( $key != 'search_keywords' && $key != 'search_category' && $key != 'filter_job_listing_region' ) :
?><input type="hidden" name="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $current_page_query_arg ); ?>" ><?php
endif;
endforeach;
endif;
?>
<?php do_action( 'job_manager_job_header_search_block_search_jobs_end' ); ?>
</div>
<?php do_action( 'job_manager_job_header_search_block_end' ); ?>
<!-- End Checkbox -->
</form>
<!-- End Search Jobs Form -->
</div>
</div>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment