Created
November 18, 2020 16:48
-
-
Save drewbaker/35a5fd05a130ae5212eeae3db4375660 to your computer and use it in GitHub Desktop.
Register custom "filter" taxonomy in WordPress
This file contains hidden or 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 a custom taxonomy my for "Work Filter" certain post types | |
*/ | |
function setup_work_filters() { | |
$labels = array( | |
'name' => 'Work filter', | |
'singular_name' => 'Work filter', | |
'search_items' => 'Search filters', | |
'popular_items' => 'Popular filters', | |
'all_items' => 'All Filters', | |
'parent_item' => null, | |
'parent_item_colon' => null, | |
'edit_item' => __( 'Edit filter' ), | |
'update_item' => __( 'Update filter' ), | |
'add_new_item' => __( 'Add new filter' ), | |
'new_item_name' => __( 'New filter' ), | |
'separate_items_with_commas' => __( 'Separate filter with commas' ), | |
'add_or_remove_items' => __( 'Add or remove filter' ), | |
'choose_from_most_used' => __( 'Choose from the most used filters' ), | |
'not_found' => __( 'No Work types found.' ), | |
'menu_name' => __( 'Filter' ) | |
); | |
$args = array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( | |
'slug' => 'filter', | |
'with_front' => false | |
), | |
'public' => true, | |
'show_in_rest' => true, | |
'show_in_graphql' => true, | |
'graphql_single_name' => 'filter', | |
'graphql_plural_name' => 'filters' | |
); | |
// What post types to enable on? | |
$types = array("page"); | |
register_taxonomy( 'filter', $types, $args ); | |
} | |
add_action( 'init', 'setup_work_filters' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment