Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 11 replies, has 2 voices.

Last updated by Jo 6 years, 2 months ago.

Assigned support staff: Dat Hoang.

Author Posts
September 4, 2014 at 7:27 am #463509

Jo

Hey,

by default WordPress doesn't show Custom Post Types on category archives (category.php, archive.php). There's a tiny function for that fixes this. It works fine. In fact this function should be default WordPress Care in my opinion.

I noticed that WPML breaks this function and I wonder why.

I deactivated all WordPress plugins and everything works fine and post get shown by the selected category. When I turn on WPML no custom posts show up. In the screenshots you can see the difference one's with WPML on, the other with WPML off.

I'm on WP 3.9.2 and WPML 3.1.7.2.

Please help me out.

thanks,

Bart

function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'nav_menu_item', 'my_custom_post_type'
		));
	  return $query;
	}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
September 4, 2014 at 10:06 am #463650

Dat Hoang

You're right. We are getting some tickets about pre_get_posts
In this case, please filter in get_posts or WP_Query.

September 4, 2014 at 10:07 am #463651

Dat Hoang

You're right. We are getting some tickets about pre_get_posts
In this case, please filter in get_posts or WP_Query.

September 4, 2014 at 10:09 am #463654

Jo

Thanks Dat,

I got if fixed this morning when I translated the category. Just one term, not all of them. Very weird.

September 4, 2014 at 10:37 am #463690

Dat Hoang

Did you try with these filers instead of pre_get_posts?

get_posts or WP_Query

Remember using the argument 'suppress_filter' => false

September 4, 2014 at 10:41 am #463693

Jo

I'm sorry but I don't understand what you're talking about.

September 4, 2014 at 10:54 am #463711

Dat Hoang

You're filtering 'pre_get_posts' right? Instead of that, now you should filter directly in get_posts and WP_Query

+ codex.wordpress.org/Template_Tags/get_posts
+ codex.wordpress.org/Class_Reference/WP_Query

September 4, 2014 at 11:11 am #463728

Jo

Ah okay,

I'm not filtering in pre_get_posts (I think). It's just a regular WordPress loop in archive.php.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; endif; ?>

My Custom Posts are shown with a regular WP_Query though.

September 5, 2014 at 2:04 am #464170

Dat Hoang

Yes, what is the result? What is your filtering code?

Note that: this is a kind of custom code and we can not make 100% sure it will work as you want. In the case, you need this quickly, please contact our certified partners https://wpml.org/documentation/support/wpml-contractors/

September 5, 2014 at 7:03 am #464255

Jo

The result is fine now with unmodified code.

By translating one term in my categories I fixed this. All other terms are untranslated. I think that's strange behaviour... The code worked fine without WPML and is broken with WPML activated.

September 5, 2014 at 8:36 am #464349

Dat Hoang

Good to know that it's working now.
You should enable WordPress Debug to troubleshoot more.

September 24, 2014 at 8:04 am #478421

Jo

Thanks.