-
AuthorPosts
-
October 21st, 2021 at 19:00 #122713
Here a picture show post meta, top one is default and bottom one is custom post type.
I’m using custom snippet to display custom post type on home, here the code.
add_action( 'pre_get_posts', 'add_my_post_types_to_query' ); function add_my_post_types_to_query( $query ) { if ( is_home() && $query->is_main_query() ) $query->set( 'post_type', array( 'post', 'rilisan' ) ); return $query; }
November 8th, 2021 at 00:21 #123411ZedCryout Creations mastermindHi,
You might need to duplicate the theme’s
content/content.php
file and rename it to match your post type and then edit theif ( 'post' == get_post_type() )
check in its code to include your post type.If you like our creations, help us share by rating them on WordPress.org.
Please check the available documentation and search the forums before starting a topic.November 10th, 2021 at 11:01 #123532Hello again,
I already duplicate
content/content.php
tocontent/rilisan.php
and edit post type to match to match it,if ( 'post' == get_post_type() )
toif ( 'rilisan' == get_post_type() )
and result still same, only work on custom archive not for home archive.But when i look at
index.php
and edit<?php get_template_part( 'content/content', get_post_format() ); ?>
to<?php get_template_part( 'content/rilisan', get_post_format() ); ?>
result are normal post didn’t show post meta and custom post type show post meta.Here picture, after editing
index.php
Is it possible to get multiple template part for home in
index.php
?
So I can add default post and custom post content incontent
folder.November 10th, 2021 at 11:43 #123533ZedCryout Creations mastermindThe default behaviour is to handle the default post type. If you edit the existing code and replace the checks for your custom post type you’re then excluding the default post type.
In any instances you’re editing type checks, you’d need to include your post type next to the default ‘post’ one, for example by replacing
if ( 'post' == get_post_type() )
with
if ( in_array( get_post_type(), array( 'post', 'rilisan' ) ) )
You could also give this plugin a try in case it accomplishes the same result without the need for manual code modifications.
Otherwise, it may be needed to also make use of WordPress’ template hierarchy, which lets you define separate archive-SLUG.php and/or category-SLUG.php files (and others) for each post type.
If you like our creations, help us share by rating them on WordPress.org.
Please check the available documentation and search the forums before starting a topic.November 10th, 2021 at 16:11 #123537Okay, I replace
if ( 'post' == get_post_type() )
withif ( in_array( get_post_type(), array( 'post', 'rilisan' ) ) )
incontent/content
and it works, I guess I need read more about wordpress codex.
Thank you.
-
AuthorPosts
The topic ‘How to show post meta on custom post type in home.’ is closed to new replies.