Ruft man im WordPress-Dashboard „Beiträge“ auf, sind oberhalb der Liste mehrere Dropdown-Felder verfügbar, um die Beiträgen zu filtern. Unter anderem lässt sich die Anzeige von Beiträgen auch auf eine einzelne Kategorie beschränken.
Für eigene Inhaltstypen mit eigenen Taxonomien kann man sich leicht selbst einen oder mehrere Filter bauen, z.B. in der functions.php
des eigenen Themes (oder Child-Themes):
function flxo_filter_post_type_by_term( $post_type, $which ) {
// the post type to filter
if ( $post_type != 'my_custom_type' ) return;
// taxonomy slugs to filter by
$taxonomies = array( 'my_custom_type_category', 'my_custom_type_tag' );
foreach ( $taxonomies as $taxonomy ) {
// Retrieve taxonomy data
$taxonomy_obj = get_taxonomy( $taxonomy );
$taxonomy_name = $taxonomy_obj->labels->name;
// Retrieve taxonomy terms
$terms = get_terms( $taxonomy );
// the filter HTML
echo "<select name='{$taxonomy}' id='{$taxonomy}' class='postform'>";
echo '<option value="">' . sprintf( esc_html__( 'Show All %s', 'flxo-webshots-linklibrary' ), $taxonomy_name ) . '</option>';
foreach ( $terms as $term ) {
printf(
'<option value="%1$s" %2$s>%3$s (%4$s)</option>',
esc_attr($term->slug),
( ( isset( $_GET[$taxonomy] ) && ( $_GET[$taxonomy] == $term->slug ) ) ? ' selected="selected"' : '' ),
esc_html($term->name),
absint($term->count)
);
}
echo '</select>';
}
}
add_filter( 'restrict_manage_posts', 'flxo_filter_post_type_by_term' );
Schreibe einen Kommentar