Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Make a Website with WordPress Custom Post Types and Fields in WordPress Custom Post Type Templates

Emma Redfoot
Emma Redfoot
2,215 Points

Where to find the PHP pages for the new Custom post types?

Where can I find the php pages for the new custom post types to download onto my local server?

3 Answers

This won't be a page it would be a template. can you share your file structure to and your post type declaration to help help you further?

Emma Redfoot
Emma Redfoot
2,215 Points

My custom post type is a map. I created the custom post type through the online wordpress dashboard. My file structure locally is a site folder with wordpress in it. The original theme file and the child theme file are saved under the themes section under wp-content. I do not see any new php files in either the local or online files of either my child theme or the parent theme. I do not know where to find my post type declaration as I created the post through the wordpress dashboard. Thanks for any suggestions!

Emma Redfoot
Emma Redfoot
2,215 Points

I used the advanced-custom-fields plug in to create the custom post type.

Luke Towers
Luke Towers
18,572 Points

If you've used a plugin to create a custom post type through the WordPress admin interface, my initial assumption would be that it stored the information for that custom post type in the database itself instead of creating a PHP file with the required declaration in it. I would highly recommend that you never create custom post types by using a plugin to do it for you.

The required PHP code to register custom post types is not difficult to understand and can be easily added to a theme (even though I wouldn't recommend attaching a custom post type to a theme's files either). The most ideal way to register and manage custom post types for a project would be to create a tiny plugin specific to that project. This way, the custom post type is not only accessible when the specific theme it is attached to. Themes should be for the presentation of a website's data and plugin's should be for the management of it.

Below is a very simple one-file plugin that you could create to manage your custom post types:

<?php
/*
Plugin Name: Project Plugin
Plugin URI: http://example.com
Description: Example description for a project-specific plugin
Version: 1.0.1
Author: Author_Name
Author URI: http://example.com
*/

// Create the map post type on WordPress initialization
add_action('init', 'create_map_post_type');
function create_map_post_type() {
    register_post_type('map',
         array(
            'labels' => array(
                'name'                  => 'Maps',
                'singular_name'         => 'Map',
                'add_new'               => 'Add New',
                'add_new_item'          => 'Add New Map',
                'edit_item'             => 'Edit Map',
                'new_item'              => 'New Map',
                'all_items'             => 'All Maps',
                'view_item'             => 'View Map',
                'search_items'          => 'Search Maps',
                'not_found'             => 'No Maps found',
                'not_found_in_trash'    => 'No Maps found in Trash',
                'parent_item_colon'     => '',
                'menu_name'             => 'Maps'
            ),
            'public' => true,
        )
    );
}

All you'd need to do is drop that code into nameofplugin.php and put that into a nameofplugin folder in the wp-content/plugins folder, and boom, you've just created a plugin that creates the custom post type 'map'.

Refer to the documentation for register_post_type() to learn more about the other arguments you can pass to it to configure your custom post type appropriately.