Archived topic
Help with custom post types
3 replies · Started by Suren on July 25, 2022
Hi team,
I'm trying to add posts from post types created using CPT UI; please help me guide the same.
Here is a more detailed video of what I mean -- https://youtu.be/XgXLqIRvDkU
Thanks
Hi Suren,
Are you wanting the Blog page to show the custom post type posts instead of the regular posts?
If so, you can give this PHP code a try:
add_filter( 'pre_get_posts', 'blog_show_cpt' );
function blog_show_cpt( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', 'your-cpt-name' );
return $query;
}
Adding PHP: https://docs.generatepress.com/article/adding-php/
I'm wanting to show custom post type as well as blog posts on the blog page
Hi there,
you can use an array in that function like so:
add_filter( 'pre_get_posts', 'blog_show_cpt' );
function blog_show_cpt( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'your-cpt-name' ) );
return $query;
}