# Custom Post Types

**URL:** <https://pressbooks.community/t/custom-post-types/217>\
**Category:** Developer Questions\
**Created:** [July 13, 2017, 8:33pm UTC](https://pressbooks.community/t/custom-post-types/217 "2017-07-13T20:33:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteelWagstaff](https://pressbooks.community/user_avatar/pressbooks.community/steelwagstaff/32/1280_2.png) [@SteelWagstaff](https://pressbooks.community/u/SteelWagstaff)\
**Post date:** [July 13, 2017, 8:33pm UTC](https://pressbooks.community/t/custom-post-types/217/1 "2017-07-13T20:33:52Z")

</div>

Hi @ned–quick question about the custom post types filter added to 4.0. If I wanted to add a custom post type to the array, what is is that I need to do now. I was planning to create a functionality plugin that looks like this:

function add\_post\_types ( $existing\_post\_types = array()) {  
$add\_custom\_types = array (  
‘glossary’ // or other post types we want to add to the permitted list  
);  
return array\_merge( $add\_custom\_types, $existing\_post\_types );  
}

add\_filter( ‘pb\_supported\_post\_types’, ‘add\_post\_types’ );

?\>

Does that look about right?

---

<div class="post-metadata">

**Author:** ![SteelWagstaff](https://pressbooks.community/user_avatar/pressbooks.community/steelwagstaff/32/1280_2.png) [@SteelWagstaff](https://pressbooks.community/u/SteelWagstaff)\
**Post date:** [July 13, 2017, 9:02pm UTC](https://pressbooks.community/t/custom-post-types/217/2 "2017-07-13T21:02:37Z")

</div>

Updated: the code above appears to be working for us on our dev server …

---

<div class="post-metadata">

**Author:** ![ned](https://pressbooks.community/user_avatar/pressbooks.community/ned/32/533_2.png) [@ned](https://pressbooks.community/u/ned)\
**Post date:** [July 13, 2017, 9:56pm UTC](https://pressbooks.community/t/custom-post-types/217/3 "2017-07-13T21:56:07Z")

</div>

My only suggestion would be to namespace your function as `add_post_types()` is pretty generic and could conflict with another plugin. Also you can make it a little more concise, like so:

```auto
function steel_add_post_types ( $post_types ) {
  return array_merge( $post_types, ['glossary'] );
}

add_filter( 'pb_supported_post_types', 'steel_add_post_types' );

```

---

<div class="post-metadata">

**Author:** ![SteelWagstaff](https://pressbooks.community/user_avatar/pressbooks.community/steelwagstaff/32/1280_2.png) [@SteelWagstaff](https://pressbooks.community/u/SteelWagstaff)\
**Post date:** [July 14, 2017, 1:58pm UTC](https://pressbooks.community/t/custom-post-types/217/4 "2017-07-14T13:58:25Z")

</div>

Thanks Ned–I’ll rename the function. I built the array because we were planning to add more than one custom post type to our actual plugin and I don’t think array\_merge can take more than two arguments, but the concision is appreciated.

---

<div class="post-metadata">

**Author:** ![ned](https://pressbooks.community/user_avatar/pressbooks.community/ned/32/533_2.png) [@ned](https://pressbooks.community/u/ned)\
**Post date:** [July 14, 2017, 2:15pm UTC](https://pressbooks.community/t/custom-post-types/217/5 "2017-07-14T14:15:23Z")

</div>

`array_merge()` only takes two arguments but the second is an array. So you could change it like so to add another post type:

```auto
function steel_add_post_types ( $post_types ) {
  return array_merge( $post_types, ['glossary', 'other-post-type'] );
}

add_filter( 'pb_supported_post_types', 'steel_add_post_types' );

```

---

<div class="post-metadata">

**Author:** ![SteelWagstaff](https://pressbooks.community/user_avatar/pressbooks.community/steelwagstaff/32/1280_2.png) [@SteelWagstaff](https://pressbooks.community/u/SteelWagstaff)\
**Post date:** [July 14, 2017, 2:30pm UTC](https://pressbooks.community/t/custom-post-types/217/6 "2017-07-14T14:30:54Z")

</div>

Nice–that makes good sense. Thanks again, Ned!
