0

I have this snippet for the "At a glance" Dashboard box to show not only posts, pages, but also custom post types. So far, so good, but now I want to exclude a special custom post type called:

avia_framework_post

What must I add to this snippet to exclude it from showing in this dashboard box?

<?php
function kb_add_cpts_to_dashboard() {
 $args = array(
 'public' => true,
 '_builtin' => false
 );

$output = 'object';
 $operator = 'and';

$post_types = get_post_types( $args, $output, $operator );
 
 foreach ( $post_types as $post_type ) {
 $num_posts = wp_count_posts( $post_type->name );
 $num = number_format_i18n( $num_posts->publish );
 $text = _n( $post_type->labels->singular_name, $post_type->labels->name, intval( $num_posts->publish ) );
 if ( current_user_can( 'edit_posts' ) ) {
 $output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $num . ' ' . $text . '</a>';
 echo '<li class="post-count ' . $post_type->name . '-count">' . $output . '</li>';
 }
 }
}

add_action( 'dashboard_glance_items', 'kb_add_cpts_to_dashboard' );
?>

Thank you.

1
  • Unset the post type from the returned array. unset( $post_types['avia_framework_post'] ); after the get_post_types call but before the foreach loop.
    – Abhik
    Commented May 13, 2023 at 14:11

1 Answer 1

1

I believe just one small edit to your code would get what you want. See if this works, just change the one if() statement to the following:

if ( current_user_can( 'edit_posts' ) && $post_type !== 'avia_framework_post' )

1
  • thank you, works fine!
    – BeeCee
    Commented May 13, 2023 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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