Marinus Klasen

Marinus Klasen

  • Development
  • Consultancy
  • Developer Resources
  • Blog
  • Contact

July 9, 2021

Post Type missing in WP_Query or get_posts (Polylang?)

Marinus Klasen

When querying multiple post_types via get_posts, there was one specific post type that didn’t show up in combination with posts or pages. Querying only that specific post type worked fine, but the combination failed, every – single – time.

After running the same arguments in a WP_Query and checking out the SQL that it used I noticed a specific term relation was injected in the SQL string. I searched the database for this specific term and it turned out to be a language term from Polylang.

Because posts and pages are automatically translated these show up fine in the query. But the other post type was not defined as supported. But, since Polylang finds supported post type, it does customise the query so that it only returns results for the english language.

The solution was easy: Go to Polylang settings and mark the post type as a supported one. Then, mark all posts in the post type as english versions.

As a result, the webinar posts now comply and all posts are showing fine!

About Marinus Klasen

Marinus has been working in software/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge.

Marinus Klasen on Twitter

This site runs on Cloudways.
It's fast isn't it?
Cloudways offers high-quality, fast and affordable hosting.

Learn more

Need a hand? Post your project and hire me and other top notch developers on Codeable.

Hire me on Codeable

Comments

  1. Peter says

    August 3, 2021 at 9:22 am

    Thank you very much, you saved me many hours of searching for solution to this problem!

    Reply
    • Marinus Klasen says

      August 3, 2021 at 9:24 am

      Beautiful!

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Ready to take action?

I'm looking forward to discuss your projects and goals!
Feel free to reach out using the contact details below.

Marinus Klasen

[email protected]
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • Storing private data with SSH on WPEngine sitesDecember 15, 2022
  • Get the HTML content of a block edit page or post in WordPressNovember 30, 2022
  • Rename Coupon code text to Discount code in WoocommerceNovember 3, 2022
  • Background-size cover in mPDFOctober 22, 2022
  • WordPress.com SSH & duplicating a WordPress.com website locallyOctober 11, 2022

Copyright © 2023 · Marinus Klasen | Webdesign by Team Rood