milan Smeets
milan Smeets

Reputation: 21

Wordpress Hide child posts of custom post type in wordpress admin

I created a custom post type called "Companies". Every time a post of post type companies is created, a child post is also created.

I would like to hide the child posts of this companies post type in the backend. Is there a way to do this?

Thanks!

Upvotes: 0

Views: 443

Answers (1)

milan Smeets
milan Smeets

Reputation: 21

I managed to do this by using the following code:

function cleanup_companies_posttype_list($query) {
  global $pagenow;
    if (isset($_GET['post_type']) && $_GET['post_type'] == 'companies' && $pagenow == 'edit.php') {
      $query->set('post_parent',0);
    }
}
add_filter('pre_get_posts', 'cleanup_companies_posttype_list');

Upvotes: 1

Related Questions