-
-
Save 5ally/f087701e3791902cfe2324daadfa86d3 to your computer and use it in GitHub Desktop.
See https://wordpress.stackexchange.com/a/384451/137402 for details.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this to your functions file. | |
function the_wpse_384435_checklist( $taxonomy, $label = null ) { | |
// Make sure the taxonomy exists. | |
if ( ! $tax = get_taxonomy( $taxonomy ) ) { | |
return false; | |
} | |
$tax_input = isset( $_GET['tax_input'] ) ? | |
(array) $_GET['tax_input'] : array(); | |
$selected_cats = ( ! empty( $tax_input[ $taxonomy ] ) ) ? | |
wp_parse_id_list( $tax_input[ $taxonomy ] ) : array(); | |
// Just modify the HTML to your very own liking. :) | |
echo '<div>'; | |
$label = $label ? $label : $tax->labels->singular_name; | |
echo '<label>Filter by ' . esc_html( $label ) . ':</label>'; | |
wpse_384435_checklist( array( | |
'taxonomy' => $taxonomy, | |
'selected_cats' => $selected_cats, | |
'checked_ontop' => false, | |
) ); | |
echo '</div>'; | |
} | |
/* Usage examples: | |
In your template files, display the checklist like so: | |
the_wpse_384435_checklist( 'salary_level', 'Salary' ); | |
the_wpse_384435_checklist( 'jobs_categories', 'Job Type' ); | |
You may also omit the second parameter and the function will use the default | |
label set when the taxonomy is registered: | |
the_wpse_384435_checklist( 'salary_level' ); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment