• Resolved eckul

    (@eckul)


    Hi I’m trying to add a dropdown to the main page the searches region. I think I am very close, I’ve used the category search dropdown as a base. I have created the dropdown but can’t get it to search correctly. Do you have any idea what I’m doing wrong? My code is below. any help would be great. Cheers

    <div class="col-md-3 col-sm-12">
    					<div class="search_region">
    						<label for="search_region"><?php _e( 'Region', 'wp-job-manager' ); ?></label>
    						<?php wp_dropdown_categories( array( 'taxonomy' => 'job_listing_region', 'hierarchical' => 1, 'show_option_all' => __( 'All Job Regions', 'wp-job-manager' ), 'name' => 'search_region', 'orderby' => 'name' ) ); ?>
    					</div>
    				</div>

    https://www.ads-software.com/plugins/wp-job-manager/

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

    (@mikejolley)

    You’ve added this where? Next to the other job filters?

    It won’t pick up this field and query for you automatically – there is more to it than that. You have to post the value, get the value, and modify the search queries…

    Thread Starter eckul

    (@eckul)

    Hi yes, I am trying to add it to the job-filters.php page. If you could point me in the right direction that would be great. Cheers

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Once you’ve added the field to job-filters.php, you need to modify the queries then to pick it up. My job tags plugin uses this filter:

    add_filter( 'job_manager_get_listings', array( $this, 'apply_tag_filter' ) );

    A sample of its apply_tag_filter method would look like:

    /**
    	 * Filter by tag
    	 */
    	public function apply_tag_filter( $args ) {
    		$params = array();
    		if ( isset( $_POST['form_data'] ) ) {
    
    			parse_str( $_POST['form_data'], $params );
    
    			if ( isset( $params['job_tag'] ) ) {
    				$tags      = array_filter( $params['job_tag'] );
    				$tag_array = array();
    
    				foreach ( $tags as $tag ) {
    					$tag = get_term_by( 'name', $tag, 'job_listing_tag' );
    					$tag_array[] = $tag->slug;
    				}
    
    				$args['tax_query'][] = array(
    					'taxonomy' => 'job_listing_tag',
    					'field'    => 'slug',
    					'terms'    => $tag_array,
    					'operator' => "IN"
    				);
    			}
    
    		}
    
    		return $args;
    	}

    You’ll notice it gets the posted value from ‘form_data’. You’ll need to do the same. Hope that gets you started.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add region dropdown on main search page’ is closed to new replies.