I have a post type shopping
and in my single.php
I am trying to get a certain template for this post type. So I did:
\\ in the single.php
get_template_part( 'template-parts/content', get_post_format() );
and in template-parts
directory, I created a file named content-shopping.php
. But no matter what, the single template used is the default content.php
.
However, if I do something like this:
if ( 'shopping' === get_post_type() ) {
get_template_part( 'template-parts/content-shopping' );
}else{
get_template_part( 'template-parts/content', get_post_format() );
}
then the template is used for that post type. I am not sure why the first method is not working. Any idea?
1 Answer
get_post_format
and get_post_type
are completely different.
Post Formats can be one of the following:
- ‘standard’ (default one)
- ‘aside’
- ‘chat’
- ‘gallery’
- ‘link’
- ‘image’
- ‘quote’
- ‘status’
- ‘video’
- ‘audio’
And shopping
is the post type you have created and not post format. You can add post format for the post type(shopping) like this
add_post_type_support( 'shopping', 'post-formats' );