-1

I want to show only one specific category posts in admin (All posts page) instead of showing all category posts.

can anyone give me an idea about that.

0

to show one specific category posts in admin all posts page (edit.php?post_type=post) you need to join term_relationships table by filtering posts_join and adding where clause by filtering posts_where.

eg.

add_filter( 'posts_join', 'hide_attachments_wpquery_join' );
function hide_attachments_wpquery_join( $join, \WP_Query $query ) {
    global $wpdb;
    if( is_admin() && $query->query['post_type'] == "post" ) {
        $join .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
    }
    return $join;
}
add_filter( 'posts_where', 'hide_attachments_wpquery_where' );
function hide_attachments_wpquery_where( $where, \WP_Query $query ) {
    global $wpdb;
    if( is_admin() && $query->query['post_type'] == "post" ) {
        // change 6 with your category/term id
        $where .= " AND ( $wpdb->term_relationships.term_taxonomy_id IN (6) )";
    }
    return $where;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.