• Resolved dbued

    (@dbued)


    Hello everybody. This is my first post in this forum and I really hope the community can help me with my problem.

    First of all: Yes, I’ve read the master list about 4.3. and I’ve read the new features posting. But none of the information can help me with my problem. I will explain why:

    Well, for better understanding: We’re a newsportal with a paywall and at the moment we serve 4 cities with fresh news. For our writers it is important that we separate each citiy in the backend, primary for a better organisation. Because of this I installed 4 different “Custom Post Types”. Each CPT gets an specific category too, because we have main news, sports news, short news etc….on several places on our site we are displaying those news with the term “show me this CPT only with this category” so we can separate the output.

    Now here’s the problem. After upgrading to WP 4.3 those CPT disappeared. But only the output. In the backend the CPT are still visible. Nothing was lost, even in the database table “wp_posts” we have still the entries in the “post_type” column. And it gets even more weird: sports news are shown, but main and short news not. Although they are saved within the same CPT.

    I deactivated all the plugins, activated WordPress Debug Mode but no warning there. So what happened there? It seems that WP is ignoring my wp_query???

    I’m not using any plugin for my CPT, but I have to admit that I copied the output of the WP Plug-In “Custom Post Type UI” to be sure I forgot nothing for my CPT. Here’s the code we’re using in the functions.php:

    function cptui_register_my_cpt_mycity() {
    		register_post_type('mycity', array(
    			'label' => 'MyCity',
    			'description' => '',
    			'public' => true,
    			'show_ui' => true,
    			'show_in_menu' => true,
    			'capability_type' => 'post',
    			'map_meta_cap' => true,
    			'hierarchical' => false,
    			'rewrite' => array('slug' => 'mycity', 'with_front' => true),
    			'query_var' => true,
    			'menu_position' => '5',
    			'menu_icon' => '/wp-content/themes/tme/assets/ico/wappen-mycity.ico',
    			'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
    			'yarpp_support' => true,
    			'taxonomies' => array('category','post_tag'),
    			'labels' => array (
    				'name' => 'MyCity',
    				'singular_name' => 'MyCity',
    				'menu_name' => 'MyCity',
    				'add_new' => 'Neuer Artikel',
    				'add_new_item' => 'Neuen Artikel hinzufügen',
    				'edit' => 'Bearbeiten',
    				'edit_item' => 'Artikel bearbeiten',
    				'new_item' => 'Neuer Artikel',
    				'view' => 'Ansehen',
    				'view_item' => 'Artikel ansehen',
    				'search_items' => 'Artikel suchen',
    				'not_found' => 'Keinen Artikel gefunden',
    				'not_found_in_trash' => 'No MyCity Found in Trash',
    				'parent' => 'Parent MyCity',
    				)
    			)
    		);
    	}
    	add_action('init', 'cptui_register_my_cpt_mycity');

    Here an example what I’m using to output the information of the CPT:

    <?php global $wp_query; query_posts( array('post_type' => array( 'mycity' ),'showposts' => 1, 'paged' => $paged, 'category__in' => array(17) ) );?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    Title, Content, etc...
    <?php endwhile; ?>
    <?php endif; ?>

    I would love to get some help here…thanks in advance!!!

Viewing 10 replies - 1 through 10 (of 10 total)
  • I don’ think you want to use query_posts().

    I think it’s better to use new WP_Query().

    Check out this Stack Exchange Answer.

    I think when you use query_posts() along with the global $wp_query… you change something that should be reset instead.

    You can tell I’m not positive. But I’m fairly certain I’m setting you on the right track.

    Perhaps someone with more CPT experience can chime in…

    Thread Starter dbued

    (@dbued)

    Hey dude, thanks for your answer. WP_Query was not the result, but I’ve found the problem thanks to your advice. While i was searching for the category parameters for WP_Query() I’ve found the following thing in the backend:

    Before Update:

    wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=10&post_type=mycity

    After Update:

    wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=3687&post_type=mycity

    So can anyone tell me why the heck wordpress changes the ID of my category while updating the DB for the new wordpress version? For what reason?????

    I had a couple of category IDs change too after my last update, trying to figure out why that might have happened.

    Moderator keesiemeijer

    (@keesiemeijer)

    It could be you had shared terms between taxonomies.

    Eliminating shared taxonomy terms in WordPress 4.3

    Probably right … I was thinking it might be something like that and going to make my way through that article even before you posted it, but it was making my eyes cross:-) Thanks for forcing me to do it.

    Moderator keesiemeijer

    (@keesiemeijer)

    Check if the category name from the changed category ID exists in another taxonomy (tags, custom taxonomy)

    It was only two categories for me, so it’s not really a big issue for me. I’m more just curious. I can’t find anything in my current site, but could this have been caused by some old tags or custom taxonomies I might have created in the past that perhaps were not deleted from the database?

    Moderator keesiemeijer

    (@keesiemeijer)

    Yes, it could be from taxonomies that don’t exist anymore. The terms from those taxonomies are not deleted from the database.

    If you register the same (old) taxonomy again the terms would show up in the wp-admin.

    Perfect, thanks so much for the info (and sorry for hijacking this thread:-)

    Thread Starter dbued

    (@dbued)

    I managed to solve this problem with a workaround. I’m using WP_Query without specific ID’s and with category slugs. Works well!

    <?php 
    
    // WP_Query arguments
    $args = array (
    	'post_type'			=> array( 'customposttype1', 'customposttype2', 'customposttype3' ),
    	'showposts'			=> 1,
    	'tax_query' => array(
             'relation' => 'AND',
             array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => array('customposttypecat1', 'customposttypecat2', 'customposttypecat3'),
                'operator' => 'IN'
             )
          )
    );
    
    // The Query
    $query = new WP_Query( $args );				
    
    if ( $query->have_posts()) : while ( $query->have_posts() ) : $query->the_post(); ?>
    
    ..... title, content, etc .....
    
    <?php 
    
    endwhile; 
    
    endif; 
    
    wp_reset_query(); 
    
    ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom Post Types disappearing after upgrade to 4.3’ is closed to new replies.