Within this tutorial, you will learn how to get the ID for any page type defined within your Episerver 7 powered website using code alone. Whenever you create a new page type within the CMS it will be given a unique ID. Often you might want to query for content based on the page type it was built from. In these instances, querying for the content by the page-type ID is the easiest option. In Episerver 6, you could use the GetPageTypeID() method. All you had to do was pass in the name of the page type and the API would return the page type Id. In Episerver 7 and upwards this has changed. You will now need to use the IContentTypeRepository. In IContentTypeRepository you have useful methods like Load<T>, Save<T>, Delete<T> and List() to get information about page types. List() is probably the most useful as it will give you a list of all page types defined in your site. You can use the API like this:

Simply swap PageType with the page type you want data about. Job done, that's all there is to do. Happy Coding 🤘