Search code examples
wordpresstwigtimber

Single custom post type template (WordPress using Timber/Twig) not working


I've been unable to get the single twig templates for a custom post type to work.

My developments.twig page correctly lists the posts in custom post type developments.

However, the single template defaults to single.twig, rather than single-development.twig. In single-development.php I have:

$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
Timber::render('single-development.twig', $context);

Like some others suggested I resaved the permalinks but that didn't help.

In timber-functions.php I have:

public function register_post_types() {
        // Use categories and tags with attachments
        register_taxonomy_for_object_type( 'category', 'attachment' );
        register_taxonomy_for_object_type( 'post_tag', 'attachment' );

        register_post_type('developments', array(
            'labels' =>
                array(
                    'name' => __( 'Developments' ),
                    'singular_name' => __( 'development' )
                ),
            'public' => true,
            'supports' => array( 'title', 'author', 'excerpt', 'custom-fields', 'revisions', 'page-attributes' ),
            'show_in_menu' => true,
            'taxonomies'  => array( 'category' ),
        ));
    }

How is this structure supposed to work.. have I missed something?


Solution

  • Your post_type called developmentS (plural), so your single file should be named single-developments.php