Jeremy Herve Avatar

That’s me. And my blog. In English and in French.


Manage your Custom Post Types on WordPress.com

I’ve talked about the WordPress.com REST API on this blog before. I even created a plugin allowing you to make use of it on your own site. This API powers WordPress.com, the desktop WordPress.com apps, and is used in more and more areas of the Jetpack plugin.

Did you know that API also allows you to manage your Custom Post Types via the WordPress.com interface?

Make your Custom Post Type available in the WordPress.com REST API

By default, that API allows you to query Posts and Pages on your site, but won’t query Custom Post Types. Luckily, Jetpack includes a filter you can use to whitelist some of your Custom Post Types, to make them available in the WordPress.com REST API. To use that filter, you can paste the following in a functionality plugin:

/**
 * Filter the list of Post Types available in the WordPress.com REST API.
 *
 * @param array $allowed_post_types Array of whitelisted Post Types.
 * @return array $allowed_post_types Array of whitelisted Post Types, including our 'ghactivity_event' Custom Post Type.
 */
function jeherve_allow_post_type_wpcom( $allowed_post_types ) {
    $allowed_post_types[] = 'ghactivity_event';
    return $allowed_post_types;
}
add_filter( 'rest_api_allowed_post_types', 'jeherve_allow_post_type_wpcom' );

Once you’ve done so, your content will be available in the WordPress.com REST API. If you go to WordPress.com/posts, or if you install one of the WordPress.com desktop apps, you’ll see the Post type in your sidebar:

Custom Post Types in the WordPress.com interface

You will then be able to create new posts or edit existing ones right from WordPress.com, without having to log in to your site.

Magic!

Reactions on the Fediverse and on the ATmosphere

2 responses

  1. Ben Avatar

    So you can have a non wordpress.com blog, and add support to the wordpress.com app for custom post types that aren’t supported by wordpress.com?

    If so that’s really clever. Presumably any custom properties aren’t managed. How did you set the icon in the editor? Is the icon just a generic one for unrecognised post types?


    1. Jeremy Avatar

      Presumably any custom properties aren’t managed.

      Yeah, post meta will require some more work before it’s ready. See this issue if you’re interested:
      https://github.com/Automattic/wp-calypso/issues/587

      How did you set the icon in the editor? Is the icon just a generic one for unrecognised post types?

      That’s a default icon. It would be nice if Calypso could pull the Dashicon you chose in wp-admin though. You should create a GitHub issue about that. If you don’t, I will 🙂



Continuez votre lecture / Keep reading

Discover more posts about or look at some of the posts suggested below.

Jeremy Herve
Jeremy Herve

WordPress, TV Series, music, kids, and board games. I think that’s probably the best way to define me in a few words. 🙂

I work at Automattic where I lead a team building tools for bloggers and creators. I talk a lot about WordPress things, but also about all things open source in general.

I post in English and in French.

I live in Brittany, France, so you’ll also find me sharing pictures from our beautiful region from time to time.

1,241 posts
194 followers