• Resolved Uprootednut

    (@uprootednut)


    Been working on custom search forms and I noticed something weird I couldn’t figure out.

    https://owenreed.co.uk.ss.strategiesuk.net/

    The search form below the slider where there is some text saying category there should be a third drop down which can be seen in the inspector looks like this :

    <select name="search_categories[]" id="search_categories" class="job-manager-category-dropdown " data-placeholder="Choose a category…" data-no_results_text="No results match" data-multiple_text="Select Some Options" style="display: none;">

    The display none seems to be added on but I have no idea where!

    It works here – https://owenreed.demo.strategiesexpress.co.uk/

    I’ve tried multiple ways to show categories ` <?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’ => __( ‘Divisions’, ‘wp-job-manager’ ), ‘name’ => ‘search_categories’, ‘orderby’ => ‘name’, ‘selected’ => $selected_category, ‘multiple’ => false ) ); ?>
    <?php endif; ?>`
    Works on the 2nd link.

    <select id="search_category" name="search_category">
      		<?php foreach ( get_job_listing_categories() as $cat ) : ?>
      			<option value="<?php echo esc_attr( $cat->term_id ); ?>"><?php echo esc_html( $cat->name ); ?></option>
      		<?php endforeach; ?>
      	</select>

    Does show but the order is wrong and I couldn’t find a way to get them the way I wanted them.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Uprootednut

    (@uprootednut)

    ok we’ve figured out whats happening.

    We’re using per_page= and it would appear if we publish more jobs then will be shown by the jobs shortcode it will add display none to the category drop down.

    On the homepage it is set to five, so if we have 6 jobs on the website it will hide the category drop down. On the vaccanies page it is set to 10 and again if we have more then 10 jobs on the site it will do the same thing here.

    Also on the vacancies page itself, just with the shortcode ‘[jobs]’ the category drop down is also set to display none by some inline style. Weird..

    https://owenreed.co.uk.ss.strategiesuk.net/vacancies/

    Any ideas?

    I can help. I have done same type of custom search form. You want to display category ?

    function job_search_func( $atts ) {
    $html = "";
    $html .='<div class="job_listings">';
    $html .='<form class="job_filters" action="/jobs/" method="GET">
    		<div class="search_jobs">
    			<div class="search_keywords">
    	      		<label for="search_keywords">Keywords</label>
    	      		<input type="text" name="search_keywords" id="search_keywords" placeholder="Keywords" value="">
    	    	</div>
    	    	<div class="search_location">
          			<label for="search_location">Location</label>
          			<input type="text" name="search_location" id="search_location" placeholder="Location" value="">
        		</div>';
    $html .= '<div class="search_categories">
    		<label for="search_categories">Category</label>';
    		$html .= job_search_job_manager_dropdown_categories( apply_filters( 'job_manager_regions_dropdown_args', array(
    
    			'show_option_all' => __( 'All Category', 'wp-job-manager-locations' ),
    			'hierarchical' => true,
    			'orderby' => 'name',
    			'taxonomy' => 'job_listing_category',
    			'name' => 'search_category',
    			'class' => 'job-manager-category-dropdown',
    			'id'              => 'search_categories',
    			'hide_empty' => 1,
    			'multiple'        => false,
    			//'selected' => isset( $atts[ 'selected_region' ] ) ? $atts[ 'selected_region' ] : ''
    
    		) ) );
    $html .= '</div>';
    $html .='<div class="search_location search_submit">
            <input type="submit" value="Search" />
        </div>
    </div>
    </form>
    </div>';
    return $html;
    }
    
    add_shortcode( 'job_search_box', 'job_search_func' );
    
    /**
     * Based on wp_dropdown_categories, with the exception of supporting multiple selected categories.
     * @see  wp_dropdown_categories
     */
    function job_search_job_manager_dropdown_categories( $args = '' ) {
    	$defaults = array(
    		'orderby'         => 'id',
    		'order'           => 'ASC',
    		'show_count'      => 0,
    		'hide_empty'      => 1,
    		'child_of'        => 0,
    		'exclude'         => '',
    		'echo'            => 1,
    		'selected'        => 0,
    		'hierarchical'    => 0,
    		'name'            => 'cat',
    		'id'              => '',
    		'class'           => 'job-manager-category-dropdown ' . ( is_rtl() ? 'chosen-rtl' : '' ),
    		'depth'           => 0,
    		'taxonomy'        => 'job_listing_category',
    		'value'           => 'id',
    		'multiple'        => true,
    		'show_option_all' => false,
    		'placeholder'     => __( 'Choose a category&hellip;', 'wp-job-manager' ),
    		'no_results_text' => __( 'No results match', 'wp-job-manager' ),
    		'multiple_text'   => __( 'Select Some Options', 'wp-job-manager' )
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    
    	if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
    		$r['pad_counts'] = true;
    	}
    
    	extract( $r );
    
    	// Store in a transient to help sites with many cats
    	$categories_hash = 'jm_cats_' . md5( json_encode( $r ) . WP_Job_Manager_Cache_Helper::get_transient_version( 'jm_get_' . $r['taxonomy'] ) );
    	$categories      = get_transient( $categories_hash );
    
    	if ( empty( $categories ) ) {
    		$categories = get_terms( $taxonomy, array(
    			'orderby'         => $r['orderby'],
    			'order'           => $r['order'],
    			'hide_empty'      => $r['hide_empty'],
    			'child_of'        => $r['child_of'],
    			'exclude'         => $r['exclude'],
    			'hierarchical'    => $r['hierarchical']
    		) );
    		set_transient( $categories_hash, $categories, DAY_IN_SECONDS * 30 );
    	}
    
    	$name       = esc_attr( $name );
    	$class      = esc_attr( $class );
    	$id         = $id ? esc_attr( $id ) : $name;
    
    	$output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "' class='" . esc_attr( $class ) . "' " . ( $multiple ? "multiple='multiple'" : '' ) . " data-placeholder='" . esc_attr( $placeholder ) . "' data-no_results_text='" . esc_attr( $no_results_text ) . "' data-multiple_text='" . esc_attr( $multiple_text ) . "'>\n";
    
    	if ( $show_option_all ) {
    		$output .= '<option value="">' . esc_html( $show_option_all ) . '</option>';
    	}
    
    	if ( ! empty( $categories ) ) {
    		include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-category-walker.php' );
    
    		$walker = new WP_Job_Manager_Category_Walker;
    
    		if ( $hierarchical ) {
    			$depth = $r['depth'];  // Walk the full depth.
    		} else {
    			$depth = -1; // Flat.
    		}
    
    		$output .= $walker->walk( $categories, $depth, $r );
    	}
    
    	$output .= "</select>\n";
    
    	//if ( $echo ) {
    		//echo $output;
    	//}
    
    	return $output;
    }

    Please paste this shortcode anywhere

    job_search_box

    It can help you

    Hello Kishores,

    thank you for this!
    Where do you paste the code?

    best
    Zetona

    [job_search_box] in a page

    and code in your function file.

    Plugin Contributor Davor

    (@davoraltman)

    Thanks for helping. Marking as resolved.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom search form’ is closed to new replies.