WP Job Manager - Custom Search field.

Hello Experts,

I'm currently working on a job search page, using the WP Job Manager plugin and Jobify theme.

I added a custom taxonomy  fleet_type and linked it to all the available job posts.

The default plugin searches Categories (Position Type), and results are displayed depending on which filters have been selected (Location, Position Type, Miles/Radius).

I want to add an extra drop down, which will be fleet types (Regional [regional], Dedicated [dedicated], OTR [otr]). If somebody selects Regional, then I want only posts with the category Regional (regional) to be displayed.

I followed a similar solution to try and make this work https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/. but it is not working.  Whatever fleet_type you pick, it will not query the results,  just shows all results or all results based on the Position Type selection.  

Can somebody look at my code, and see what I am doing wrong, and how I can fix this?

Code I'm using for the job-filters.php . and web page can be seen here - https://wdevl.cretecarrier.com/truck-driving-jobs/

Excuse the layout, I can get that fixed, once i have it pulling fleet_type posts.

<?php
/**
 * Filters in `[jobs]` shortcode.
 *
 * This template can be overridden by copying it to yourtheme/job_manager/job-filters.php.
 *
 * @see         https://wpjobmanager.com/document/template-overrides/
 * @author      Automattic
 * @package     WP Job Manager
 * @category    Template
 * @version     1.21.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

wp_enqueue_script( 'wp-job-manager-ajax-filters' );

do_action( 'job_manager_job_filters_before', $atts );
?>

<form class="job_filters">
	<?php do_action( 'job_manager_job_filters_start', $atts ); ?>

	<div class="search_jobs">
		<?php do_action( 'job_manager_job_filters_search_jobs_start', $atts ); ?>

	<!--	<div class="search_keywords">
			<label for="search_keywords"><?php _e( 'Keywords', 'wp-job-manager' ); ?></label>
			<input type="text" name="search_keywords" id="search_keywords" placeholder="<?php esc_attr_e( 'Keywords', 'wp-job-manager' ); ?>" value="<?php echo esc_attr( $keywords ); ?>" />
		</div> -->

		<div class="search_location">
			<label for="search_location"><?php _e( 'Location', 'wp-job-manager' ); ?></label>
			<input type="text" name="search_location" id="search_location" placeholder="<?php esc_attr_e( 'Enter City, State, or Zipcode', 'wp-job-manager' ); ?>" value="<?php echo esc_attr( $location ); ?>" />
		</div>
		

		<?php if ( get_option( 'job_manager_enable_categories' ) ) : ?>
		
		<div class="search_categories">
			<label for="search_categories"><?php _e( 'Category', 'jobify' ); ?></label>
			<?php job_manager_dropdown_categories( array(
				'taxonomy' => 'job_listing_category',
				'hierarchical' => 1,
				'show_option_all' => __( 'Position Type', 'jobify' ),
				'name' => 'search_categories',
				'orderby' => 'name',
				'multiple' => false,
			) ); ?>
		</div>		
		
				
		<!--- <div class="search_categories">
			<label for="search_categories"><?php _e( 'Category', 'jobify' ); ?></label>
			<?php job_manager_dropdown_categories( array(
				'taxonomy' => 'fleet_type',
				'hierarchical' => 1,
				'show_option_all' => __( 'Fleet Type', 'jobify' ),
				'name' => 'search_categories',
				'orderby' => 'name',
				'multiple' => false,
			) ); ?> 
		</div> -->
		
				<?php 
/**
 * This can either be done with a filter (below) or the field can be added directly to the job-filters.php template file!
 *
 * job-manager-filter class handling was added in v1.23.6
 */
add_action( 'job_manager_job_filters_search_jobs_end', 'filter_by_fleet_type_field' );
function filter_by_fleet_type_field() {
	?>
	<div class="search_categories">
		<label for="search_categories"><?php _e( 'fleet_type', 'wp-job-manager' ); ?></label>
		<select name="filter_by_fleet_type" class="job-manager-filter">
			<option value=""><?php _e( 'Any Fleet', 'wp-job-manager' ); ?></option>
			<option value="regional"><?php _e( 'Regional', 'wp-job-manager' ); ?></option>
			<option value="dedicated"><?php _e( 'Dedicated', 'wp-job-manager' ); ?></option>
			<option value="otr"><?php _e( 'OTR', 'wp-job-manager' ); ?></option>
		</select>
	</div>
	<?php
}
/**
 * This code gets your posted field and modifies the job search query
 */
add_filter( 'job_manager_get_listings', 'filter_by_fleet_type_field_query_args', 10, 2 );
function filter_by_fleet_type_field_query_args( $query_args, $args ) {
	if ( isset( $_POST['form_data'] ) ) {
		parse_str( $_POST['form_data'], $form_data );
		// If this is set, we are filtering by salary
		if ( ! empty( $form_data['filter_by_fleet_type'] ) ) {
			$selected_range = sanitize_text_field( $form_data['filter_by_fleet_type'] );
			switch ( $selected_range ) {
				case 'Regional' :
					$query_args['meta_query'][] = array(
						'key'     => 'regional',
						'value'   => 'Regional',
						'compare' => '=',
						'type'    => 'CHAR'
					);
				break;
				case 'Dedicated' :
					$query_args['meta_query'][] = array(
						'key'     => 'dedicated',
						'value'   => 'Dedicated',
						'compare' => '=',
						'type'    => 'CHAR'
					);
				break;
				case 'OTR' :
					$query_args['meta_query'][] = array(
						'key'     => 'otr',
						'value'   => 'OTR',
						'compare' => '=',
						'type'    => 'CHAR'
					);
				break;
				default :
					$query_args['meta_query'][] = array(
						'key'     => '',
						'value'   => array_map( 'absint', explode( '-', $selected_range ) ),
						'compare' => 'BETWEEN',
						'type'    => 'CHAR'
					);
				break;
			}
			// This will show the 'reset' link
			add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
		}
	}
	return $query_args;
}?>
		

		<?php endif; ?>
		
		

		<?php do_action( 'job_manager_job_filters_search_jobs_end', $atts ); ?>
	</div>

	<?php do_action( 'job_manager_job_filters_end', $atts ); ?>
</form>

<?php do_action( 'job_manager_job_filters_after', $atts ); ?>

<noscript><?php _e( 'Your browser does not support JavaScript, or it is disabled. JavaScript must be enabled in order to view listings.', 'wp-job-manager' ); ?></noscript>

Open in new window

Jon ImmsWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lenamtlCommented:
Hi,

If you have an active license you can request support, you will save a lot of time..
https://wpjobmanager.com/support/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jon ImmsWeb DeveloperAuthor Commented:
I already did that. They don't offer custom support.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.