0
votes

I’ve created a custom post type in WordPress for events. My index.php page is based off the twenty Twelve theme in that it sets up The Loop and then passes off the rendering to a partial template:

<?php get_header();

if (have_posts()) {
    while (have_posts()) {
        the_post();
        get_template_part('content', get_post_format());
    }
}
else {
    get_template_part('content', 'none');
}

get_sidebar();
get_footer();

However, when viewing an event post, get_post_format() just returns an empty string (I’d expect it to return event or similar) and in turn only the content.php template partial is loaded rather than content-event.php which is what I was expecting and actually want.

How can I make my event post type report event as its post format?

2

2 Answers

2
votes

I guess you confused post formats and post types. What you need here is get_post_type().

1
votes

Use:

if(get_post_type()):
    get_template_part( 'content', get_post_type() );
else:
    get_template_part( 'content', get_post_format() );
endif;