• Resolved carboneum

    (@carboneum)


    Hello,

    I am looking for a way to display the search_location filter in the search jobs form as a Dropdown menu with all the locations i have written in my jobs.

    Currently I am able to change the field type with the plugin WP Job Manager Field Editor ( https://plugins.smyl.es/wp-job-manager-field-editor/ ). I changed the form field search_location from input to select(Dropdown).

    Then I changed the file job-filters.php in wp-content\plugins\wp-job-manager\templates
    line 18,

    from:

    <input type="text" name="search_location" id="search_location" placeholder="<?php esc_attr_e( 'Location', 'wp-job-manager' ); ?>" value="<?php echo esc_attr( $location ); ?>" />

    to:

    <?php
    	$job_locations = get_custom_field_config( 'job_location', 'options' );
    	if ( is_array( $job_locations ) ):
    ?>
    		<select class="" name="search_location" id="search_location">
    			<option value="" <?php selected( empty( $location ) || ! in_array( $location, $job_locations ) ); ?>><?php _e( 'Any Location' ); ?></option>
    			<?php foreach( $job_locations as $loc_val => $loc_label ): ?>
    				<option value="<?php echo esc_attr( $loc_val ); ?>" <?php selected( $location, $loc_val ); ?>><?php echo esc_attr( $loc_label ); ?></option>
    		<?php endforeach; ?>
    		</select>
    <?php endif; ?>

    I followed this Tutorial:
    https://gist.github.com/tripflex/602d419f061114ef5cb3a4c538777bed

    I tried it also with an Filter like in this Tutorial:
    https://wpjobmanager.com/document/editing-job-submission-fields/
    https://sceptermarketing.com/wp-job-manager-create-drop-form-fields/

    Unfortunately this is only for the job Submission Fields not for the job search that will show when you use the shortcode [job] in you pages.

    The above explained way gives me a Dropdown but it doesn’t show me all Locations i have posted in my jobs, because i manually ad them to the select form. Is there a way to retrieve the locations form the database and display them in the Dropdown, so I only have to post a new job with an location and the user can filter the location with the Dropdown when he searches for jobs.

    Thank you very much.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • hello and good day dear carboneum,

    many thanks sharing your ideas & plans about the enhancement regarding the
    way to display the search_location filter. That sounds very very interesting.

    i also have same things in mind; but untill now i have not tested the plugins of smyl so far: The field editor ( cf .smyl.es/wp-job-manager-field-editor/ )

    display the search_location filter in the search jobs form as a Dropdown menu with all the locations i have written in my jobs.
    Currently I am able to change the field type with the plugin WP Job Manager Field Editor ( https://plugins.smyl.es/wp-job-manager-field-editor/ ). I changed the form field search_location from input to select(Dropdown).

    as mentioned above: the job manager field editor i have not tested so far. ( cf .smyl.es/wp-job-manager-field-editor/ ).

    but i am very very glad that you share the hint to the following article:

    How to Add a Drop-Down Form

    the author states: “you’ll place this in the custom function that you copy from the Docs page in the link above: https://sceptermarketing.com/wp-job-manager-create-drop-form-fields/

     $fields['job']['job_location'] = array(
     'label' => __( 'Job Location', 'job_manager' ),
     'type' => 'select',
     'required' => true,
     'options' => array('', 'alabama' => 'Alabama', 'alaska' => 'Alaska', 'arizona' => 'Arizona', 'arkansas' => 'Arkansas', 'california' => 'California', 'colorado' => 'Colorado', 'connecticut' => 'Connecticut', 'delaware' => 'Delaware', 'dc' => 'DC', 'florida' => 'Florida', 'georgia' => 'Georgia', 'hawaii' => 'Hawaii', 'idaho' => 'Idaho', 'illinois' => 'Illinois', 'indiana' => 'Indiana', 'iowa' => 'Iowa', 'kansas' => 'Kansas', 'kentucky' => 'Kentucky', 'louisiana' => 'Louisiana', 'maine' => 'Maine', 'maryland' => 'Maryland', 'massachusetts' => 'Massachusetts', 'michigan' => 'Michigan', 'minnesota' => 'Minnesota', 'mississippi' => 'Mississippi', 'missouri' => 'Missouri', 'montana' => 'Montana', 'nebraska' => 'Nebraska', 'nevada' => 'Nevada', 'new hampshire' => 'New Hampshire', 'new jersey' => 'New Jersey', 'new mexico' => 'New Mexico', 'new york' => 'New York', 'north carolina' => 'North Carolina', 'north dakota' => 'North Dakota', 'ohio' => 'Ohio', 'oklahoma' => 'Oklahoma', 'oregon' => 'Oregon', 'pennsylvania' => 'Pennsylvania', 'rhode island' => 'Rhode Island', 'south carolina' => 'South Carolina', 'south dakota' => 'South Dakota', 'tennessee' => 'Tennessee', 'texas' => 'Texas', 'utah' => 'Utah', 'vermont' => 'Vermont', 'virginia' => 'Virginia', 'washington' => 'Washington', 'west virginia' => 'West Virginia', 'wisconsin' => 'Wisconsin', 'wyoming' => 'Wyoming', 'out of us' => 'Out of US'),
     'placeholder' => '',
     'priority' => 3
     );

    and besides that:

    Then, in the function where you’re adding / editing fields on the back end of the site, you’ll add the following:

    ..with the following code:

    
     $fields['_job_location'] = array(
     'label' => __( 'Job Location', 'job_manager' ),
     'type' => 'select',
     'options' => array('', 'alabama' => 'Alabama', 'alaska' => 'Alaska', 'arizona' => 'Arizona', 'arkansas' => 'Arkansas', 'california' => 'California', 'colorado' => 'Colorado', 'connecticut' => 'Connecticut', 'delaware' => 'Delaware', 'dc' => 'DC', 'florida' => 'Florida', 'georgia' => 'Georgia', 'hawaii' => 'Hawaii', 'idaho' => 'Idaho', 'illinois' => 'Illinois', 'indiana' => 'Indiana', 'iowa' => 'Iowa', 'kansas' => 'Kansas', 'kentucky' => 'Kentucky', 'louisiana' => 'Louisiana', 'maine' => 'Maine', 'maryland' => 'Maryland', 'massachusetts' => 'Massachusetts', 'michigan' => 'Michigan', 'minnesota' => 'Minnesota', 'mississippi' => 'Mississippi', 'missouri' => 'Missouri', 'montana' => 'Montana', 'nebraska' => 'Nebraska', 'nevada' => 'Nevada', 'new hampshire' => 'New Hampshire', 'new jersey' => 'New Jersey', 'new mexico' => 'New Mexico', 'new york' => 'New York', 'north carolina' => 'North Carolina', 'north dakota' => 'North Dakota', 'ohio' => 'Ohio', 'oklahoma' => 'Oklahoma', 'oregon' => 'Oregon', 'pennsylvania' => 'Pennsylvania', 'rhode island' => 'Rhode Island', 'south carolina' => 'South Carolina', 'south dakota' => 'South Dakota', 'tennessee' => 'Tennessee', 'texas' => 'Texas', 'utah' => 'Utah', 'vermont' => 'Vermont', 'virginia' => 'Virginia', 'washington' => 'Washington', 'west virginia' => 'West Virginia', 'wisconsin' => 'Wisconsin', 'wyoming' => 'Wyoming', 'out of us' => 'Out of US'),
     'placeholder' => '',
     );

    and finally …scepter

    “I’m creating a drop-down field for states. To add a select input of your own, simply replace all of my states with your options, so for example:”

     $fields['_job_location'] = array(
     'label' => __( 'Job Location', 'job_manager' ),
     'type' => 'select',
     'options' => array('', 'option1' => 'Option 1', 'option2' => 'Option 2'),
     'placeholder' => '',
     );

    and finally septer:

    I left the first array item blank (the empty single quotes). Being that this is a required field, the submit button will trigger a check of that field. To select the first item, the user would have to select a different item and then select the first item to trigger a change.

    for what i have understood; this shoud work as an added Drop-Down Form.

    Many many thanks dear carboneum for sharing this ideas.

    Question: did not this code work for you?

    you have mentioned that you want to fetch data out of the db. Well i have to think about this – and how this will provide your goals.

    Finally: carboneum . well i hope were able to solve your problems…

    best regards
    say hello

    Thread Starter carboneum

    (@carboneum)

    Thank you very much say_hello for the responde,

    the above mentioned way gives me the ability to show the search_locaton filter as an dropdown. Unfortunately there are many locations for my jobs, some of them I don’t know at the moment, the client will tell me the location as soon as he give the job to post.

    For example a client gives me a job with a location that is not in the custom field list, I have created with the wp job manager field editor plugin.

    Then I have to go to the wordpress backend under jobs->job fields click on edit the Meta Key search_location and under options I have to add the location for the new job.

    Like you say, the best way is to fetch data out of the db.

    This way I would only have to add a new job, write the job location to the new job and the location would show in the dropdown on the page when a user searches for jobs.

    Could you please provide me where wp job manager stores the locations, then I would find a way to fetch the data as an String Array, split the Strings and loop them to show in the dropdown. This would be the best practice, I think.

    I am not so familiar with php and just started my wordpress development but I assume this would work, what you think?

    Thank you again for your answer and your help, I appreciate that very much.

    Sincerely yours,
    carboneum

    hello dear Carboneum,

    many thanks for the quick reply. Great to hear from you.

    well – i think that this is the way you should go.

    where wp job manager stores the locations, then I would find a way to fetch the data as an String Array, split the Strings and loop them to show in the dropdown. This would be the best practice, I think.

    Exacly – i for one would do it exacly this way.

    dear carboneum: i also have same things in mind; but untill now i have not tested the plugins

    Well – carboneum i am not so good in coding – so at the moment i guess that i cannot be of much help with the concrete work that fits and meeds all your specs. But i hope there are some guys here that can help out.

    For what i see here in this thread. A plugin that meets the various needs of filter / search would be great.

    To you and all your endeavours dear carboneum all the best.

    Please keep us posted – as you move ahead.

    greetings sayhello

    • This reply was modified 6 years, 3 months ago by Jan Dembowski.
    Plugin Contributor Adam Heckler

    (@adamkheckler)

    Sorry, but we aren’t able to help actually write code for custom requests like this. 🙁 You may want to look into one of these services for help:

    https://codeable.io/?ref=l1TwZ

    http://studio.envato.com/

    https://jobs.wordpress.net/

    That said, you should be able to use this guide to base your code off of:

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

    … particularly the “Adding a Salary Filter to the Job Search Form” section.

    Of course, the way your filter works will not be the same, but that page shows you basically how to add an additional filter to the Jobs page.

    Sorry I can’t be of more help here! 🙁

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change search_location field to dropdown and receive locations from Database’ is closed to new replies.