Polylang plugin not including a custom post type in search results is a common challenge when dealing with multilingual content in WordPress. Polylang, by default, might not include all custom post types in search results, especially if they haven’t been properly configured to be translatable or included in searches. Here are some steps and considerations to solve this issue:

1. Ensure Custom Post Type is Translatable

  • Make Custom Post Type Translatable: In your WordPress admin area, go to Languages > Settings in the Polylang menu. Under the ‘Custom post types and Taxonomies’ section, make sure your custom post type is checked to be translatable.

2. Include Custom Post Type in Search Results

  • Modify Search Query: If your custom post type is not appearing in search results, you may need to modify the search query to include it. This can be done by adding a filter to your theme’s functions.php file or a site-specific plugin.

Replace 'your_custom_post_type' with the actual slug of your custom post type.

3. Check Language Configuration

  • Verify Language Setup: Ensure that each post or page within your custom post type has a language assigned. Polylang relies on the language information to include content in search results properly.

4. Polylang Search Filter

  • Use Polylang’s Search Filter: Polylang offers a search filter that can be adjusted to include all languages or specific languages in search results, which can also affect the visibility of your custom post types.

In this code snippet:

  • Replace 'your_custom_post_type' with the slug of your actual custom post type.
  • The filter function my_custom_polylang_search_filter is hooked to pre_get_posts, which is a WordPress hook that allows modification of the query before it’s executed.
  • By modifying the 'post_type' parameter of the query, we include our custom post types alongside the default ones like posts and pages.
  • The commented-out line $query->set( 'lang', '' ); demonstrates how you could modify the query to search across all languages by setting the 'lang' parameter to an empty string. You can adjust this as needed (for example, specifying a language code to limit the search to a particular language).

5. Debugging

  • Debugging Tools: Utilize debugging plugins like Query Monitor to see how the search queries are being constructed and executed. This can help identify if the custom post type is being queried correctly but not displayed for some other reason.

6. Polylang Pro

  • Consider Polylang Pro: If you’re using the free version of Polylang, some features might not be available. Polylang Pro offers extended functionalities, which might include better support for custom post types in searches.

7. Check for Plugin Conflicts

  • Plugin Conflicts: Sometimes, other plugins may interfere with how search results are generated. Try deactivating other plugins temporarily to see if that solves the issue.

8. Custom Plugin or Code

  • If all else fails, consider developing a custom plugin or adding custom code that explicitly includes your custom post types in search results, taking Polylang’s language features into account.