{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/WP-Job-Manager/issues/521","labels_url":"https://api.github.com/repos/Automattic/WP-Job-Manager/issues/521/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/WP-Job-Manager/issues/521/comments","events_url":"https://api.github.com/repos/Automattic/WP-Job-Manager/issues/521/events","html_url":"https://github.com/Automattic/WP-Job-Manager/issues/521","id":103432625,"number":521,"title":"Adding a Salary Filter to the Job Search Form (advanced)","user":{"login":"truetesterphp","id":10518894,"avatar_url":"https://avatars.githubusercontent.com/u/10518894?v=3","gravatar_id":"","url":"https://api.github.com/users/truetesterphp","html_url":"https://github.com/truetesterphp","followers_url":"https://api.github.com/users/truetesterphp/followers","following_url":"https://api.github.com/users/truetesterphp/following{/other_user}","gists_url":"https://api.github.com/users/truetesterphp/gists{/gist_id}","starred_url":"https://api.github.com/users/truetesterphp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/truetesterphp/subscriptions","organizations_url":"https://api.github.com/users/truetesterphp/orgs","repos_url":"https://api.github.com/users/truetesterphp/repos","events_url":"https://api.github.com/users/truetesterphp/events{/privacy}","received_events_url":"https://api.github.com/users/truetesterphp/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-27T05:36:22Z","updated_at":"2015-10-05T15:38:56Z","closed_at":"2015-10-05T15:38:56Z","body":"Adding a Salary Filter to the Job Search Form (advanced) Not working\r\n\r\nhttps://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/ \r\n\r\n\r\n\r\n<?php \r\n/**\r\n * This can either be done with a filter (below) or the field can be added directly to the job-filters.php template file!\r\n *\r\n * job-manager-filter class handling was added in v1.23.6\r\n */\r\nadd_action( 'job_manager_job_filters_search_jobs_end', 'filter_by_salary_field' );\r\nfunction filter_by_salary_field() {\r\n\t?>\r\n\t<div class=\"search_categories\">\r\n\t\t<label for=\"search_categories\"><?php _e( 'Salary', 'wp-job-manager' ); ?></label>\r\n\t\t<select name=\"filter_by_salary\" class=\"job-manager-filter\">\r\n\t\t\t<option value=\"\"><?php _e( 'Any Salary', 'wp-job-manager' ); ?></option>\r\n\t\t\t<option value=\"upto20\"><?php _e( 'Up to $20,000', 'wp-job-manager' ); ?></option>\r\n\t\t\t<option value=\"20000-40000\"><?php _e( '$20,000 to $40,000', 'wp-job-manager' ); ?></option>\r\n\t\t\t<option value=\"40000-60000\"><?php _e( '$40,000 to $60,000', 'wp-job-manager' ); ?></option>\r\n\t\t\t<option value=\"over60\"><?php _e( '$60,000+', 'wp-job-manager' ); ?></option>\r\n\t\t</select>\r\n\t</div>\r\n\t<?php\r\n}\r\n/**\r\n * This code gets your posted field and modifies the job search query\r\n */\r\nadd_filter( 'job_manager_get_listings', 'filter_by_salary_field_query_args', 10, 2 );\r\nfunction filter_by_salary_field_query_args( $query_args, $args ) {\r\n\tif ( isset( $_POST['form_data'] ) ) {\r\n\t\tparse_str( $_POST['form_data'], $form_data );\r\n\t\t// If this is set, we are filtering by salary\r\n\t\tif ( ! empty( $form_data['filter_by_salary'] ) ) {\r\n\t\t\t$selected_range = sanitize_text_field( $form_data['filter_by_salary'] );\r\n\t\t\tswitch ( $selected_range ) {\r\n\t\t\t\tcase 'upto20' :\r\n\t\t\t\t\t$query_args['meta_query'][] = array(\r\n\t\t\t\t\t\t'key'     => '_job_salary',\r\n\t\t\t\t\t\t'value'   => '20000',\r\n\t\t\t\t\t\t'compare' => '<',\r\n\t\t\t\t\t\t'type'    => 'NUMERIC'\r\n\t\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\t\tcase 'over60' :\r\n\t\t\t\t\t$query_args['meta_query'][] = array(\r\n\t\t\t\t\t\t'key'     => '_job_salary',\r\n\t\t\t\t\t\t'value'   => '60000',\r\n\t\t\t\t\t\t'compare' => '>=',\r\n\t\t\t\t\t\t'type'    => 'NUMERIC'\r\n\t\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\t\tdefault :\r\n\t\t\t\t\t$query_args['meta_query'][] = array(\r\n\t\t\t\t\t\t'key'     => '_job_salary',\r\n\t\t\t\t\t\t'value'   => array_map( 'absint', explode( '-', $selected_range ) ),\r\n\t\t\t\t\t\t'compare' => 'BETWEEN',\r\n\t\t\t\t\t\t'type'    => 'NUMERIC'\r\n\t\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t// This will show the 'reset' link\r\n\t\t\tadd_filter( 'job_manager_get_listings_custom_filter', '__return_true' );\r\n\t\t}\r\n\t}\r\n\treturn $query_args;\r\n}\r\n\r\n?>"},"comment":{"url":"https://api.github.com/repos/Automattic/WP-Job-Manager/issues/comments/145574162","html_url":"https://github.com/Automattic/WP-Job-Manager/issues/521#issuecomment-145574162","issue_url":"https://api.github.com/repos/Automattic/WP-Job-Manager/issues/521","id":145574162,"user":{"login":"mikejolley","id":90977,"avatar_url":"https://avatars.githubusercontent.com/u/90977?v=3","gravatar_id":"","url":"https://api.github.com/users/mikejolley","html_url":"https://github.com/mikejolley","followers_url":"https://api.github.com/users/mikejolley/followers","following_url":"https://api.github.com/users/mikejolley/following{/other_user}","gists_url":"https://api.github.com/users/mikejolley/gists{/gist_id}","starred_url":"https://api.github.com/users/mikejolley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikejolley/subscriptions","organizations_url":"https://api.github.com/users/mikejolley/orgs","repos_url":"https://api.github.com/users/mikejolley/repos","events_url":"https://api.github.com/users/mikejolley/events{/privacy}","received_events_url":"https://api.github.com/users/mikejolley/received_events","type":"User","site_admin":false},"created_at":"2015-10-05T15:38:56Z","updated_at":"2015-10-05T15:38:56Z","body":"Confirmed the snippet is fine, so it must be your implementation. As mentioned, the code goes in your theme functions.php file or a custom plugin. Take care not to double nest the `<?php` tags.\r\n\r\nFYI this is not a support area,"}}