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

    (@mikejolley)

    It looks like you’ve made some bad customisations to the predefined-regions plugin, or ajax-filters.php https://ww.wp.xz.cn/plugins/wp-job-manager-locations/ handles the region field, and its usually a dropdown, but on your page it’s hidden for some reason.

    Thread Starter ouni

    (@ouni)

    this my code in WP_Job_Manager_Ajax i dont have ajax-filters.php

    <?php
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    /**
     * WP_Job_Manager_Ajax class.
     */
    class WP_Job_Manager_Ajax {
    
    	/**
    	 * Constructor
    	 */
    	public function __construct() {
    		add_action( 'wp_ajax_nopriv_job_manager_get_listings', array( $this, 'get_listings' ) );
    		add_action( 'wp_ajax_job_manager_get_listings', array( $this, 'get_listings' ) );
    	}
    
    	/**
    	 * Get listings via ajax
    	 */
    	public function get_listings() {
    		global $wp_post_types;
    
    		$result            = array();
    		$search_location   = sanitize_text_field( stripslashes( $_POST['search_location'] ) );
    		$search_keywords   = sanitize_text_field( stripslashes( $_POST['search_keywords'] ) );
    		$search_categories = isset( $_POST['search_categories'] ) ? $_POST['search_categories'] : '';
    		$search_types = isset( $_POST['search_typess'] ) ? $_POST['search_typess'] : '';
    		$filter_job_types  = isset( $_POST['filter_job_type'] ) ? array_filter( array_map( 'sanitize_title', (array) $_POST['filter_job_type'] ) ) : null;
    		$types             = get_job_listing_types();
    		$post_type_label   = $wp_post_types['job_listing']->labels->name;
    
    		if ( is_array( $search_categories ) ) {
    			$search_categories = array_filter( array_map( 'sanitize_text_field', array_map( 'stripslashes', $search_categories ) ) );
    		} else {
    			$search_categories = array_filter( array( sanitize_text_field( stripslashes( $search_categories ) ) ) );
    		}
    
    		$args = array(
    			'search_location'    => $search_location,
    			'search_keywords'    => $search_keywords,
    			'search_categories'  => $search_categories,
    			'job_types'          => is_null( $filter_job_types ) ? '' : $filter_job_types + array( 0 ),
    			'orderby'            => sanitize_text_field( $_POST['orderby'] ),
    			'order'              => sanitize_text_field( $_POST['order'] ),
    			'offset'             => ( absint( $_POST['page'] ) - 1 ) * absint( $_POST['per_page'] ),
    			'posts_per_page'     => absint( $_POST['per_page'] )
    		);
    
    		if ( isset( $_POST['featured'] ) && ( $_POST['featured'] === 'true' || $_POST['featured'] === 'false' ) ) {
    			$args['featured'] = $_POST['featured'] === 'true' ? true : false;
    		}
    
    		ob_start();
    
    		$jobs = get_job_listings( apply_filters( 'job_manager_get_listings_args', $args ) );
    
    		$result['found_jobs'] = false;
    
    		if ( $jobs->have_posts() ) : $result['found_jobs'] = true; ?>
    
    			<?php while ( $jobs->have_posts() ) : $jobs->the_post(); ?>
    
    				<?php get_job_manager_template_part( 'content', 'job_listing' ); ?>
    
    			<?php endwhile; ?>
    
    		<?php else : ?>
    
    			<?php get_job_manager_template_part( 'content', 'aucun offers d\'emploi' ); ?>
    
    		<?php endif;
    
    		$result['html']    = ob_get_clean();
    		$result['showing'] = array();
    
    		// Generate 'showing' text
    		$showing_types = array();
    		$unmatched     = false;
    
    		foreach ( $types as $type ) {
    			if ( in_array( $type->slug, $filter_job_types ) ) {
    				$showing_types[] = $type->name;
    			} else {
    				$unmatched = true;
    			}
    		}
    
    		if ( sizeof( $showing_types ) == 1 ) {
    			$result['showing'][] = implode( ', ', $showing_types );
    		} elseif ( $unmatched ) {
    			$last_type           = array_pop( $showing_types );
    			$result['showing'][] = implode( ', ', $showing_types ) . " & $last_type";
    		}
    
    		if ( $search_categories ) {
    			$showing_categories = array();
    
    			foreach ( $search_categories as $category ) {
    				$category_object = get_term_by( is_numeric( $category ) ? 'id' : 'slug', $category, 'job_listing_category' );
    
    				if ( ! is_wp_error( $category_object ) ) {
    					$showing_categories[] = $category_object->name;
    				}
    
    			}
    
    			$result['showing'][] = implode( ', ', $showing_categories );
    		}
    		if ( $search_types ) {
    			$showing_typess = array();
    
    			foreach ( $search_types as $typess ) {
    				$typess_object = get_term_by( is_numeric( $typess ) ? 'id' : 'slug', $typess, 'job_listing_typess' );
    
    				if ( ! is_wp_error( $typess_object ) ) {
    					$showing_typess[] = $typess_object->name;
    				}
    
    			}
    
    			$result['showing'][] = implode( ', ', $showing_typess );
    		}
    
    		if ( $search_keywords ) {
    			$result['showing'][] = '&ldquo;' . $search_keywords . '&rdquo;';
    		}
    
    		$result['showing'][] = $post_type_label;
    
    		if ( $search_location ) {
    			$result['showing'][] = sprintf( __( 'located in &ldquo;%s&rdquo;', 'wp-job-manager' ), $search_location );
    		}
    
    		if ( 1 === sizeof( $result['showing'] ) ) {
    			$result['showing_all'] = true;
    		}
    
    		$result['showing'] = apply_filters( 'job_manager_get_listings_custom_filter_text', sprintf( __( ' %s', 'wp-job-manager' ), implode( ' ', $result['showing'] ) ) );
    
    		// Generate RSS link
    		$result['showing_links'] = job_manager_get_filtered_links( array(
    			'filter_job_types'  => $filter_job_types,
    			'search_location'   => $search_location,
    			'search_categories' => $search_categories,
    			'search_types' => $search_types,
    			'search_keywords'   => $search_keywords
    		) );
    
    		// Generate pagination
    		if ( isset( $_POST['show_pagination'] ) && $_POST['show_pagination'] === 'true' ) {
    			$result['pagination'] = get_job_listing_pagination( $jobs->max_num_pages, absint( $_POST['page'] ) );
    		}
    
    		$result['max_num_pages'] = $jobs->max_num_pages;
    
    		echo '<!--WPJM-->';
    		echo json_encode( apply_filters( 'job_manager_get_listings_result', $result, $jobs ) );
    		echo '<!--WPJM_END-->';
    
    		die();
    	}
    }
    
    new WP_Job_Manager_Ajax();
    Plugin Author Mike Jolley

    (@mikejolley)

    Thread Starter ouni

    (@ouni)

    this my code in 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 ); ?>
    <?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 wp_dropdown_categories( array( ‘taxonomy’ => ‘job_listing_category’, ‘hierarchical’ => 1, ‘show_option_all’ => __( ‘Secteur activité’, ‘wp-job-manager’ ), ‘name’ => ‘search_categories’, ‘orderby’ => ‘name’, ‘selected’ => $selected_category ) ); ?>
    <?php endif; ?>
    </div>
    <?php endif; ?>
    <br />

    <div class=”job_types”>

    <select name=”filter_job_type”><option >Type d’emploi</option>
    <?php foreach ( get_job_listing_types() as $type ) : ?>

    <option value=”<?php echo $type->slug; ?>” id=”job_type_<?php echo $type->slug; ?>”><?php echo $type->name; ?></option>

    <?php endforeach; ?>
    </select>

    </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>
    <br />
    <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>

    <?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)

    I would suggest starting by removing or renaming that file and seeing if regions works after doing that. If your customisations above are causing the issue you’ll know its not an issue in Job Manager or the regions plugin, but in your own code.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘filter does not work for some location’ is closed to new replies.