Hi, i’m working with custom post types in ambrosia.com.br and with those inserts in functions.php it works fine for search, feed and main query, but i could not show the custom posts on Archive pages. Can you please help with this? Thanks in advance,
function add_post_types_to_loop_and_feed($query) {
if ($query->is_feed() || $query->is_main_query() && $query->is_front_page()) {
$query->set(‘post_type’, array(‘post’, ‘custom1’, ‘custom2’, ‘custom3’));
}
}
add_action(‘pre_get_posts’, ‘add_post_types_to_loop_and_feed’);
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( ‘post_type’, array( ‘post’, ‘page’, ‘feed’, ‘custom1’, ‘custom2’, ‘custom3’));
}
return $query;
}
add_filter( ‘the_search_query’, ‘searchAll’ );
Hello,
This guide should help: http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/
Thank you!
Hi, thanks but we already have archive pages for custom post types, what we need is to show custom post types in the commom archive pages, alongside the “post” kind. For example, to display also events in the same archive pages.
Also, is possible to load the custom post types in the mega menu as well? Since it shows only “post” custom type. Thanks!
Besides that, what about the search, archive and so on? the theme says work with custom post types but does not really work…
Hello ambrosiacombr,
Sorry, but the custom posts type will do not appears on Archive and Search pages, sorry! You should display them to another custom page made by you. For more information about Custom Post Type, please read our documentation from here -> https://forum.tagdiv.com/custom-post-type-support/
Thanks for your understanding!