Skip to content

Instantly share code, notes, and snippets.

@RatzeR
Created January 2, 2021 14:32
Show Gist options
  • Save RatzeR/97e492f0c1d05083592e4a78ad41c148 to your computer and use it in GitHub Desktop.
Save RatzeR/97e492f0c1d05083592e4a78ad41c148 to your computer and use it in GitHub Desktop.
Wordpress - Gutenberg: Get all PostTypes of your installation
export default withSelect((select, props) => {
const { attributes } = props;
const { selectedPostType } = attributes;
let postTypesArray = [];
const getPostTypes = select("core").getPostTypes();
// Gets all PostTypes and add's the name and the slug of each PostType to an array
if (getPostTypes != null) {
getPostTypes.map((type) => {
postTypesArray.push({ name: type.labels.singular_name, slug: type.slug });
});
}
return {
postTypes: postTypesArray
};
})(ExampleEdit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment