Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Mike Jolley

    (@mikejolley)

    You’ll need to be more specific about what is and isn’t working. The tutorial as-is works fine.

    adding the filter to job-filters.php ends up with blank screen.
    salary in admin and frontent works good, but i can;t get the filter running.
    I have categories and tags.

    the whole job-filters.php:

    <?php wp_enqueue_script( 'wp-job-manager-ajax-filters' ); ?>
    
    <?php 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( 'Location', 'wp-job-manager' ); ?>" value="<?php echo esc_attr( $location ); ?>" />
    		</div>
    
    		<?php if ( $categories ) : ?>
    			<?php foreach ( $categories as $category ) : ?>
    				<input type="hidden" name="search_categories[]" value="<?php echo sanitize_title( $category ); ?>" />
    			<?php endforeach; ?>
    		<?php elseif ( $show_categories && ! is_tax( 'job_listing_category' ) && get_terms( 'job_listing_category' ) ) : ?>
    			<div class="search_categories">
    				<label for="search_categories"><?php _e( 'Category', 'wp-job-manager' ); ?></label>
    				<?php if ( $show_category_multiselect ) : ?>
    					<?php job_manager_dropdown_categories( array( 'taxonomy' => 'job_listing_category', 'hierarchical' => 1, 'name' => 'search_categories', 'orderby' => 'name', 'selected' => $selected_category, 'hide_empty' => false ) ); ?>
    				<?php else : ?>
    					<?php job_manager_dropdown_categories( array( 'taxonomy' => 'job_listing_category', 'hierarchical' => 1, 'show_option_all' => __( 'Any category', 'wp-job-manager' ), 'name' => 'search_categories', 'orderby' => 'name', 'selected' => $selected_category, 'multiple' => false ) ); ?>
    				<?php endif; ?>
    			</div>
    		<?php endif; ?>
    <?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_salary_field' );
    function filter_by_salary_field() {
    	?>
    	<div class="search_categories">
    		<label for="search_categories"><?php _e( 'Salary', 'wp-job-manager' ); ?></label>
    		<select name="filter_by_salary" class="job-manager-filter">
    			<option value=""><?php _e( 'Any Salary', 'wp-job-manager' ); ?></option>
    			<option value="upto20"><?php _e( 'Up to $20,000', 'wp-job-manager' ); ?></option>
    			<option value="20000-40000"><?php _e( '$20,000 to $40,000', 'wp-job-manager' ); ?></option>
    			<option value="40000-60000"><?php _e( '$40,000 to $60,000', 'wp-job-manager' ); ?></option>
    			<option value="over60"><?php _e( '$60,000+', '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_salary_field_query_args', 10, 2 );
    function filter_by_salary_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_salary'] ) ) {
    			$selected_range = sanitize_text_field( $form_data['filter_by_salary'] );
    			switch ( $selected_range ) {
    				case 'upto20' :
    					$query_args['meta_query'][] = array(
    						'key'     => '_job_salary',
    						'value'   => '20000',
    						'compare' => '<',
    						'type'    => 'NUMERIC'
    					);
    				break;
    				case 'over60' :
    					$query_args['meta_query'][] = array(
    						'key'     => '_job_salary',
    						'value'   => '60000',
    						'compare' => '>=',
    						'type'    => 'NUMERIC'
    					);
    				break;
    				default :
    					$query_args['meta_query'][] = array(
    						'key'     => '_job_salary',
    						'value'   => array_map( 'absint', explode( '-', $selected_range ) ),
    						'compare' => 'BETWEEN',
    						'type'    => 'NUMERIC'
    					);
    				break;
    			}
    			// This will show the 'reset' link
    			add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
    		}
    	}
    	return $query_args;
    }
    		<?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>
    Plugin Author Mike Jolley

    (@mikejolley)

    This code is not intended to go in there. It’s intended to go in theme functions.php as stated a the top of the article.

    Thread Starter truetester

    (@jitendar)

    Hi Mike Jolley,

    I have Follow https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/ tutorial .

    Add the field to the frontend: Working Fine
    Add the field to admin : Working Fine

    But Adding a Salary Filter to the Job Search Form (advanced) Not working.

    <?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_salary_field' );
    function filter_by_salary_field() {
    	?>
    	<div class="search_categories">
    		<label for="search_categories"><?php _e( 'Salary', 'wp-job-manager' ); ?></label>
    		<select name="filter_by_salary" class="job-manager-filter">
    			<option value=""><?php _e( 'Any Salary', 'wp-job-manager' ); ?></option>
    			<option value="upto20"><?php _e( 'Up to $20,000', 'wp-job-manager' ); ?></option>
    			<option value="20000-40000"><?php _e( '$20,000 to $40,000', 'wp-job-manager' ); ?></option>
    			<option value="40000-60000"><?php _e( '$40,000 to $60,000', 'wp-job-manager' ); ?></option>
    			<option value="over60"><?php _e( '$60,000+', '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_salary_field_query_args', 10, 2 );
    function filter_by_salary_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_salary'] ) ) {
    			$selected_range = sanitize_text_field( $form_data['filter_by_salary'] );
    			switch ( $selected_range ) {
    				case 'upto20' :
    					$query_args['meta_query'][] = array(
    						'key'     => '_job_salary',
    						'value'   => '20000',
    						'compare' => '<',
    						'type'    => 'NUMERIC'
    					);
    				break;
    				case 'over60' :
    					$query_args['meta_query'][] = array(
    						'key'     => '_job_salary',
    						'value'   => '60000',
    						'compare' => '>=',
    						'type'    => 'NUMERIC'
    					);
    				break;
    				default :
    					$query_args['meta_query'][] = array(
    						'key'     => '_job_salary',
    						'value'   => array_map( 'absint', explode( '-', $selected_range ) ),
    						'compare' => 'BETWEEN',
    						'type'    => 'NUMERIC'
    					);
    				break;
    			}
    			// This will show the 'reset' link
    			add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
    		}
    	}
    	return $query_args;
    }

    Above code add salary dropdown in job search form but search result not showing correctly , when i have filter job by salary showing all posts.

    please suggest me what i do??

    Plugin Author Mike Jolley

    (@mikejolley)

    Questions;

    have you changed any of the above snippets in any way?
    what version of job manager are you using?
    where is the site located?

    Thread Starter truetester

    (@jitendar)

    No , I am not change any thing in code.Using wp Job manger Latest version.
    Project is at my local end .
    Now i Have use “wordpress directory theme listify” theme.

    Ok – posted in functions, and works. I had error before.
    thanks! ??

    just one question – how to move the filter dropdown above search button?

    Plugin Author Mike Jolley

    (@mikejolley)

    We don’t include a search button. if its being added by a filter, change the add_action priorities.

    https://codex.www.ads-software.com/Function_Reference/add_action

    Thread Starter truetester

    (@jitendar)

    Hi @mike Jolley

    What about my issue ??
    you get my point or not …

    Please reply me

    Plugin Author Mike Jolley

    (@mikejolley)

    Id need to see more. Can you use our private support area?

    Thread Starter truetester

    (@jitendar)

    No i am not using .

    Plugin Author Mike Jolley

    (@mikejolley)

    Thread Starter truetester

    (@jitendar)

    you need we get help form here :
    https://wpjobmanager.com/contact/

    Thread Starter truetester

    (@jitendar)

    i would be great if you help in resolve this issue ??

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Not working Adding a Salary Filter to the Job Search Form (advanced)’ is closed to new replies.