Custom Taxonomy & Term Posts Return "No Posts"
-
Hi Dave,
For some reason, when I select a custom taxonomy that I’ve created, it returns no posts. I’ve also tried with the custom taxonomy created by this plugin: https://ww.wp.xz.cn/plugins/the-events-calendar/; and nothing shows up there as well.
I’m currently using the “widget.php” template with no changes to it. Could you please help me work out what might be the issue?
Thank you in advance. I appreciate that you’re very active in supporting your great plugin!
This is the functions.php portion for my custom taxonomy/post-type:
add_action( 'init', 'create_staff_type' ); function create_staff_type() { register_taxonomy('staff-type','staff', array( 'label' => __( 'Staff Type' ), 'labels' => array( 'edit_item' => __("Edit Staff Type") ), 'rewrite' => array( 'slug' => 'staff-type', 'with_front' => true, 'hierarchical' => true ), 'hierarchical' => true, 'query_var' => true, '_builtin' => false, 'paged' => true, 'public' => true ) ); register_post_type( 'staff', /* this can be seen at the URL as a parameter and a unique id for the custom post */ array( 'labels' => array( 'name' => __( 'People','People' ), /* The Label of the custom post */ 'singular_name' => __( "People" ), /* The Label of the custom post */ 'name_admin_bar' => __( "People"), 'add_new_item' => __("Add New People") ), 'public' => true, 'rewrite' => array('slug' => 'people', 'with_front' => true, 'hierarchical' => true), /* The slug of the custom post */ 'supports' => array( 'title', 'editor','thumbnail','tags' ), /* enable basic for text editing */ 'query_var' => true, 'taxonomies' => array('staff-type'), 'can_export' => true, 'show_ui' => true, // UI in admin panel '_builtin' => false, // It's a custom post type, not built in 'hierarchical' => true, 'show_in_menu' => true, 'has_archive' => true ) );flush_rewrite_rules( false ); } add_filter('rewrite_rules_array', 'mmp_rewrite_rules'); function mmp_rewrite_rules($rules) { $newRules = array(); $newRules['people/%staff-type%/([^/]+)/(.+)/(.+)/?$'] = 'index.php?staff=$matches[3]'; $newRules['people/%staff-type%/(.+)/?$'] = 'index.php?staff-type=$matches[1]'; return array_merge($newRules, $rules); } function filter_post_type_link($link, $post) { if ($post->post_type != 'staff') return $link; if ($cats = get_the_terms($post->ID, 'staff-type')) { $link = str_replace('%staff-type%', current( $cats )->slug, $link ); // see custom function defined below } return $link; } add_filter('post_type_link', 'filter_post_type_link', 10, 2);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Custom Taxonomy & Term Posts Return "No Posts"’ is closed to new replies.