php - Issue querying specific custom post type -


i made website while ago, custom post types , working ok, have add new custom post type , made loop new custom post type , 'post' post type.

something this:

$args = array (     'post_type' => array( 'post', 'newsletter' ),         'posts_per_page' => -1,         'order'     => 'desc' ); 

for reason not working...

i have same array other post type , working fine.

$args = array (     'post_type' => array( 'post', 'events' ),         'posts_per_page' => -1,         'order'     => 'desc' ); 

now here weird part:

if have 'post'-'events' (events old custom post type) works, shows both post custom post types, if have 'post'-'newsletter' (newsletter new custom post type) shows post, if have 'events'-'newsletter' shows events,

if create new custom post type 'newsletter2', , if have 'newsletter'-'newsletter2' works, shows both custom post types, if have 'post'-'newsletter2' shows 'post'

so... looks old custom post types not working new custom post types reason... ideas???

thanks!!!

here 'newsletter' custom post type (by way of custom post types same, except instead of newsletter have 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 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 shows post post_type posts.     <?php        // end loop      endwhile;     endif;     wp_reset_query(); ?> 

it extemely hard correctly answer question, bounty.

what quite interesting whole scenario code stays same across board, issue not related code used register post type.

lets @ possible issues , defaults

  • wp_query ( if using get_posts, stays same, get_posts uses wp_query )has set preset values parameters, , excluded default if not explicitely set. lets @ 2 can influence result:

    • post_type -> default post

    • post_status -> defaults publish logged out users, publish , private logged in users

as have set post_type include post types, other option can think of, looking @ above, newsletter post type posts has either not being published or have custom post status assigned them via plugin or custom code.

you need explore possibility. try adding 'post_status' => 'any' custom query , see if posts newsletter post type. i'm not entirely sure if work if have custom post status assigned posts.

apart this, don't have offer regarding issue.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -