I have a ACF relationship field for a custom post type, properties. Moreover, the content of these properties can either be in English or Spanish. When I use a ACF relationship field to associate properties to a user on the user edit page -- /wp/wp-admin/user-edit.php
-- everything works as expected, and I can select from the relationship drop down the properties I want for this user.
My question is this: how can I write a query inside this filter such that only the English properties appear, regardless of the language of the page (English or Spanish) which is set by the WPML toggle? I know how to write such a query in SQL:
SELECT *
FROM wp_2_posts
INNER JOIN wp_2_icl_translations
ON wp_2_icl_translations.element_id = wp_2_posts.id
AND wp_2_icl_translations.language_code = 'en'
WHERE wp_2_posts.post_type = 'properties';
But the filter requires that changes be made to $args
which adhere to WP_Query. I do not know how to write the above INNER JOIN
on wp_2_icl_translations
to only show custom post types properties in English. Can someone please instruct me how so that I can get the acf filter to work the way I need it to?
posts_clauses
hookadd_filter('acf/fields/relationship/query/name=properties', function($args, $field, $post_ID) {....}, 10,3)
and instead replace that filter with this hook developer.wordpress.org/reference/hooks/posts_clauses ?$args
that is passed toWP_Query
, which allows me to only select the posts in English. I was hoping that I could make an$args
array that allows me include thewp_2_icl_translations
in some way so that I can scope the posts to be only in english. But by what you are telling me, it sounds like there's no DSL for$args
that would allow me to write such a join.