WPML + ACF and filtering
Hi,
i’m using the latest Admin Columns Pro, WPML and ACF.
We are building and art gallery site. French and English.
I have a CPT “Artworks”. When I’m in the Artworks CPT listing, i made a column from an ACF relationship field “Artist” and turned filtering ON.
The problem is: when i want want to filter the Artworks by Artist, all the artists names are duplicated : BOTH French and English appears in the filter dropdown.
Thanks for helping me out!
Hello,
Unfortunately, we don’t have an integration with WPML, so the only way to fix this is to use one of our or default WordPress hooks, to filter the records. For the filtering drop-down, we have the following hook that you can use.
I’m not sure if you’re a developer, but you could have a look at the example.
The variable args
also contains option
which contains key=>value pairs of the options that will be displayed in the dropdown. You can loop over those options and filter only the options from a specific language. Or maybe WPML does have a method to get those values for a specific language in which case you can use that one to populate the options yourself instead of using our logic.
I hope that will help you further or give you an idea of how you could tackle this issue with WPML.
Hi!
Thanks for you answer. Weird thing this morning…went back to the admin and now it works OK ¯\_(ツ)_/¯
Guess i’ll look into your hook with my developper if it comes back.
I have another question if i may :
I took a function from WPML that duplicates the post on creation / update…so let say i cahge the name of an artist, it’ll be automatically changed on the French version.
My question is : with the inline editing of AC, that function is not triggered…is there a way to trigger the function when using inline editing?
For reference, here’s the function :
add_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
function my_duplicate_on_publishh( $post_id ) {
if ( 'exhibitions' == get_post_type( $post ) ) {
$post = get_post( $post_id );
// don't save for autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// dont save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}
// we need this to avoid recursion see add_action at the end
remove_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
// make duplicates if the post being saved
// #1. itself is not a duplicate of another or
// #2. does not already have translations
$is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
if ( !$is_translated ) {
do_action( 'wpml_admin_make_post_duplicates', $post_id );
}
// must hook again - see remove_action further up
add_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
}
}
Thank you very much!
Hmm, that is indeed strange, but I’m glad it works now.
You can have a look at the following hook in our plugin to trigger your own method.
The first example shows how you can at least trigger the save_post
hook by firing update_post()
.
You hook right now is written on the ‘insert_post’ hook which runs only once (I expect) when you create a post. You might want to consider writing this for a post update.
Thank you for your quick answer! Will look into that.
The function i posted works on post creation/update.
Hi,
quick question here, as I’m no expert developper.
Last time we had WPML showing post in both languages on a given page, was the fact that we needed to add ‘suppress_filters’ => false in the wp_query.
I don’t know if it could be related to the filter choices, is there a way to add arguments to the query Admin Columns is making to generate the filter choices?
Also, WPML seems to offer a way to query specific language IDs :
wpml_object_id
Get the ID in the current language or in another language you specify
More details here : https://wpml.org/wpml-hook/wpml_object_id/
Hope i’m clear and i’m making sense ;)
Hi,
I understand what you want, but unfortunately, this is almost impossible.
Every column has it’s own logic to find the available options for filtering.
So if you want to ‘fix’ it for a specific column, I could try to find a way to do that, but to do this automatically for every column, I would not recommend it.
Hi Stefan!
I need this fix for 2 post types and 3 specific columns :
SERIES : filter by artist (artist is a ACF relationship field)
ARTWORKS : filter by serie (another ACF relationship field) and filter by artist (same field as above)
Thank you very much for your help and i hope you can find a solution!
Unfortunately, all those columns run through custom SQL. And there is no hook available to alter the query.
So the only way for you to get what you want is by using the following filter and completely try to set the options yourself by running your own query. This way you completely ignore the default logic that just looks in the database and searches for any available values for the meta key that is related to the column.
You probably want to cache this result, since our logic still runs before you overwrite the values.
You can use the following snippet to set the cache to 5 minutes instead of the default 10 seconds if I’m correct.
add_filter( 'acp/filtering/cache/seconds', function( $seconds ){
return 300;
} ,10, 1 );
Hi Stefan,
thank you i’ll have a look with my developper.
I’ll get back to you here if we have questions.
If we do not find a solution, do you take paid customization contracts?
Thanks!
You must be logged in to reply to this topic.