Created
January 2, 2021 14:32
-
-
Save RatzeR/97e492f0c1d05083592e4a78ad41c148 to your computer and use it in GitHub Desktop.
Wordpress - Gutenberg: Get all PostTypes of your installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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