How to add new tab to admin list of posts and handle result list

Admin post queries can be filtered just like frontend queries using pre_get_posts and checking for is_admin. add_action( ‘views_edit-post’, ‘remove_edit_post_views’ ); function remove_edit_post_views( $views ) { $views[‘pre’] = ‘<a href=”‘.admin_url().’edit.php?pre=pre”>My Special Posts</a>’; return $views; } add_action(‘pre_get_posts’, ‘my_special_list’); function my_special_list( $q ) { $scr = get_current_screen(); if ( is_admin() && ( $scr->base === ‘edit’ ) && $q->is_main_query() … Read more

get custom post type categories

A brute force solution that works for any post-taxonomy relationship: global $wpdb; // set the target relationship here $post_type=”post”; $taxonomy = ‘category’; $terms_ids = $wpdb->get_col( $wpdb->prepare( ” SELECT tt.term_id FROM {$wpdb->term_relationships} tr, {$wpdb->term_taxonomy} tt, {$wpdb->posts} p WHERE 1=1 AND tr.object_id = p.id AND p.post_type=”%s” AND p.post_status=”publish” AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy =’%s’ “, $post_type, … Read more

Remove “Get Shortlink” button in admin of custom post type

If you filter pre_get_shortlink and return anything but false WordPress will not create a shortlink with its own logic. If your return value is empty, the shortlink UI will not be printed. Combining both leads us to: add_filter( ‘pre_get_shortlink’, ‘__return_empty_string’ ); If you want to restrict the filter to a specific post type, check the … Read more

Is it possible to make tag archive page specific to Custom Post Type?

If I understood correctly, you want a archive template for terms of core tag taxonomy that includes only your portfolio custom post type. The best way is to use the pre_get_posts action hook to set post_type argument of the query to ‘portfolio’: add_action(‘pre_get_posts’, ‘query_post_type’); function query_post_type($query) { //Limit to main query, tag queries and frontend … Read more

Custom post type with specific category structure

I think you’ve arrived at the structure that WP doesn’t quite support. Let’s start with following premises: Taxonomies exist for grouping posts. Hierarchical taxonomies can have multiple level of grouping (with larger groups encompassing smaller groups). But what you had drafted is something else — taxonomy grouping another taxonomy. Simply put that’s not in the … Read more