WP Option Tree Post Checkboxes & Select ignoring admin language


Option Tree can generate a list of checkboxes displaying your posts (or any other post-type). But the generated checkboxes don’t take in the language as Option Tree uses get_posts to fetch the posts from the DB. So you will end up a with a long list of posts where some might have the same title and you can’t distinguish one language from the other.
5 lines of code to the rescue!
As the WordPress Documentation states:

get_posts uses ‘suppress_filters’ => true as default

So all filters are suppressed. And this is the problem: WPML hooks in via filters to localize posts and those are suppressed in this moment.
But we are lucky. Option Tree has implemented filters and this is where we hook in:

ot-functions-option-types.php (line ~1869)

A quick method to filter Option Tree post-checkbox type by language. Just paste it into your functions.php

function filter_ot_type_post_checkbox_query($args, $field_id) {
$args['suppress_filters'] = false;
return $args;
add_filter('ot_type_post_checkbox_query', 'filter_ot_type_post_checkbox_query', 99, 2);


Further reading:


If this can be solved via WPML or Option Tree without any additional code please let me know. I haven’t really searched for it as this are 5 more lines of code so not that kind of big deal

Leave a Reply

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