Disply Custom Posts Types on hompage

Hi

Firstly great themes! Love them all.

I have a custom post type I have created and want to display them in with the normal posts. Apparently this can be done and there are many variations that tell us to edit the functions.php file or even the index.php file. I have tried both files, each with variations of the code supplied by blogs and forums (some examples are below).

So the questions is, where exactly in Travelify can I put some code to mix the custom post types in with the normal post types, and indeed which code (if any) below is correct?

–My custom post type is named ‘recipesposttype’

Thanks!!


add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

	if ( is_home() && $query->is_main_query() )
		$query->set( 'post_type', array( 'post', 'page', 'recipesposttype' ) );

	return $query;
}


 add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && false == $query->query_vars['suppress_filters'] )
$query->set( 'post_type', array(
'post', 'page', 'recipesposttype' ) );
    return $query;
 }  

<?php
if( is_home() ){
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array('post_type'=>array(
'post','page','album','movie','recipesposttype'
),'paged'=>$paged ) );
}
?>


// Show posts of 'post', 'book' ,'movie' ,'page' 'joke', 'event' post types on home page
add_action( 'pre_get_posts', 'add_custom_post_types_to_home_page' );

function add_custom_post_types_to_home_page( $query ) {
    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'recipesposttype' ) );
    return $query;
}

First solution should work just fine and code needs be added inside functions.php file.

However, there might be some styling problems with blog archive as some styling is specific to posts, some to blogs and your custom post type will have another styling. Nothing major but still there might be some problems.

I did a quick test with this code to test it with Pages on added inside blog and they were working just fine. Here is code I used.

add_filter( 'pre_get_posts', 'travelify_get_posts' );

function travelify_get_posts( $query ) {

	if ( is_home() && $query->is_main_query() )
		$query->set( 'post_type', array( 'post', 'page' ) );

	return $query;
}

Ah ok, that sounds simple enough, however I tried this and it didn’t work, I’m pretty new to this so please bear with me!

I added the code, with the name of the custom post type:

add_filter( 'pre_get_posts', 'travelify_get_posts' );

function travelify_get_posts( $query ) {

	if ( is_home() && $query->is_main_query() )
		$query->set( 'post_type', array( 'post', 'page', 'recipe-schema'  ) );

	return $query;
}

To the bottom of the functions.php file, after this bit:

}
endif; // travelify_setup

?>

Then it had the code display at the top of the admin page:

And the front end:

Perhaps there is a certain place within the functions.php file it needs to go?

By the way, the custom page type I am wrangling with is the one created by the plugin “Recipe Schema”:

It appears that their custom post type is called ‘recipe-schema’.

Code you added is now outside open and closing tags which means that it is ignored and/or treated as HTML like it is in your case.

Make sure to add it after

endif; // travelify_setup

but before

?>