I made this website a while ago, with some custom post types and everything was working OK, now I have to add a new custom post type and made a loop with this new custom post type and the 'post' post type.
something like this:
$args = array (
'post_type' => array( 'post', 'newsletter' ),
'posts_per_page' => -1,
'order' => 'DESC'
);
For some reason this is not working...
I have the same array for other post type and is working fine.
$args = array (
'post_type' => array( 'post', 'events' ),
'posts_per_page' => -1,
'order' => 'DESC'
);
Now here is the weird part:
If I have 'post'-'events' (events is an old custom post type) it works, shows both post custom post types, If I have 'post'-'newsletter' (newsletter is the new custom post type) it only shows post, If I have 'events'-'newsletter' it only shows events,
If I create a new custom post type 'newsletter2', and If I have 'newsletter'-'newsletter2' it works, shows both custom post types, but if I have 'post'-'newsletter2' it only shows 'post'
So... it looks like the old custom post types are not working with the new custom post types for some reason... any ideas???
Thanks!!!
Here is the 'newsletter' custom post type (by the way all of my custom post types are exactly the same, except that instead of newsletter they have their own name 'events', 'people', 'newsletter2')
function custom_post_newsletter() {
$labels = array(
'name' => __( 'Newsletter' ),
'singular_name' => __( 'New Newsletter' )
);
$args = array(
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', ),
'taxonomies' => array( '', 'post_tag' ),
'hierarchical' => false,
'menu_icon' => 'dashicons-format-aside',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 7,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'rewrite' => array( 'slug' => _x('newsletter', 'URL Slug', 'theTheme')),
);
register_post_type( 'newsletter', $args );
}
add_action( 'init', 'custom_post_newsletter', 0 );
here is the loop:
$args = array (
'post_type' => array( 'newsletter', 'post' ),
'posts_per_page' => -1,
'order' => 'DESC',
'post_status' => 'any',
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();?>
<li><? the_title(); ?></li> //here only shows post post_type posts.
<?php
// end loop
endwhile;
endif;
wp_reset_query(); ?>