I’ve created some Custom Posts for my WordPress page and I can work fine with them. I can create a new one, edit it and display it in “archive-custom_post_type_name.php” and many more things. I can even use the same category as a normal post.
My huge problem is that I can’t display them as a normal post in my website. I want to display mixed between normal posts.
I tryed:
add_action( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'actualizacion', 'notificacion' ) );
return $query;
}
But nothing happens. I also tryed:
add_action( 'pre_get_posts', 'add_mi_cpt' );
/**
* @param WP_Query $query
* @return WP_Query
*/
function add_mi_cpt( $query ) {
if ( $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'LISTA_CPT' ) );
return $query;
}
In my wp-admin I can see my Custom Posts between the normal posts, ut my problem with that snippet is that my webpage then gives me a 404 error.
It’s anyway to create Custom Post Types and work with theme as normal posts so I can display all theme mixed in my website?
Thanks!
—EDITED—
I changed my first snippet and now Custom Post Types displays alright in my WP-Admin “Show all posts” page, but not in the website:
function add_my_post_types_to_query( $query ) {
if ( is_admin() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'My_Custom_Post_Type_List' ) );
return $query;
}
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
—EDITED 2.0—
Maybe next step is to change the Loop in page.php to display that custom post types in the loop? My loop looks like this:
<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
?>
<?php get_template_part( 'content','page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php
endwhile;
endif;
?>