2

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(); ?>
Mario Sanchez Maselli
  • 1,021
  • 1
  • 12
  • 25
  • Please share your code for how you have registered the `newsletter` post type. – rnevius Jun 19 '15 at 05:49
  • 2
    If everything exept `newsletter` works using the same way to register the post types, then you have a naming convention clash somewhere. – Pieter Goosen Jun 19 '15 at 06:08
  • Is not that is not working, is working but not with the old post-types.. if I display it alone it works, but if I tried to display it with old post types it doesnt work... and if I add another new custom post type it works... newsletter-newsletter2 it works fine. – Mario Sanchez Maselli Jun 19 '15 at 06:21

2 Answers2

2

It is really extemely hard to correctly answer your question, even with a bounty.

What really is quite interesting about this whole scenario is that your code stays the same across the board, so your issue is not related to the code used to register your post type.

Lets look at possible issues and defaults

  • WP_Query ( if you are using get_posts, this stays the same, get_posts uses WP_Query )has set preset values to its parameters, and some are completely excluded by default if not explicitely set. Lets look at the two which can influence the result:

    • post_type -> Default post

    • post_status -> Defaults publish for logged out users, publish and private for logged in users

As you have set post_type to include your post types, the only other option I can think of, looking at the above, is that the newsletter post type posts has either not being published or you have a custom post status assigned to them via a plugin or custom code.

You need to explore this possibility. Try adding 'post_status' => 'any' to your custom query and see if you get posts back from the newsletter post type. I'm not entirely sure if this will work if you have a custom post status assigned to the posts.

Apart from this, I really don't have anything to offer regarding this issue.

Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55
  • Thanks for your help, but still no change at all :(. I change the loop, and add the post_status and sill the same... except for private of course that it didn't show anything because all of the posts are publish. – Mario Sanchez Maselli Jun 29 '15 at 05:52
  • newsletter post type is showed always if its alone or with newsletter2 post type or with whatever new post type I create.. the problem is with the old post types that still not working. – Mario Sanchez Maselli Jun 29 '15 at 05:54
  • Shot in the dark, change your priority from `0` to `11` when registering your post type. Before you carry on, take a back up of your db and then repair your db. There might be something wrong your db. Here a [link](http://www.google.co.za/search?hl=en&redir_esc=&client=tablet-android-samsung&source=android-browser-suggest&v=141338691&qsubts=1435561090577&action=devloc&q=wordpress+repair+db) to help you. Also try reinstalling wordpress, deactivate your plugins and switch to a bundled theme – Pieter Goosen Jun 29 '15 at 07:00
  • Thanks for still helping me :D, I add the 11 and no change at all. I tried to repair the table and I was not able to so a follow this post http://stackoverflow.com/questions/10377334/the-storage-engine-for-the-table-doesnt-support-repair-innodb-or-myisam and then I was able to repair it, but still no change :( – Mario Sanchez Maselli Jun 29 '15 at 08:18
  • The plugins that I have enable are the ACF and the WPML and thats it – Mario Sanchez Maselli Jun 29 '15 at 08:19
  • Have you tried disabling them and retesting. I have a feeling that there might be an issue with WPML. Try disabling them, flush your permalinks and try your query again. Also, do the same with your theme. The only last possible thing I can think of is a custom filter stuffing you around – Pieter Goosen Jun 29 '15 at 08:34
  • Thanks for all the help dude I found it!!!!! finally it was under WMPL it has this option to Make "custom_postype" translatable and when I cliked on it it worked.... such a stupid thing... but thanks for all the suggestions you earned the bounty :D – Mario Sanchez Maselli Jun 29 '15 at 08:36
  • Glad you found the issue. You had my brain sweating here, hahahaha. Enjoy :-) – Pieter Goosen Jun 29 '15 at 08:41
0

Perhaps you have a theme and/or plugin that already creates a 'newsletter' CPT?

You can use "get post types" to see all the post types you currently have:

https://codex.wordpress.org/Function_Reference/get_post_types
Web Guy
  • 92
  • 1
  • 11
  • Did you read the whole thing... I wrote that I also create new custom post types ex. newsletter2 and still not working. – Mario Sanchez Maselli Jun 29 '15 at 05:46
  • Just to check out any possible outcome... I created a new post type newpost and print all the custom post types as you suggested and everything looks OK, but still no change when looping on the post types. New custom posy types ones works with new one, but old custom post types dont work new ones. – Mario Sanchez Maselli Jun 29 '15 at 06:10