Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable taxonomy term translations #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions wp-graphql-wpml.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,18 @@ function wpgraphqlwpml__switch_language_to_all_for_query(array $args)
return $args;
}

/**
* Remove the `get_term` filter added by WPML during WPGraphQL requests.
* This filter forces WPML to adjust term ids *before* other queries are
* run. There is a WPML setting named `auto_adjust_ids` that will turn
* off this feature, but it should never be on for GraphQL queries.
*/
function wpgraphqlwpml__remove_term_adjust_id_filter() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to double check this, I am currently working on filtering menus and menu items and had a case where I actually need to get the adjusted ids.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rburgst no problem! We could probably set it conditionally if needed. We were lucky enough to not need any menu data for our project but the adjusted ids caused some serious havoc with Gatsby pulling translated terms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we could use this or the constant below and set them around the resolver functions if that would work better for you.

global $sitepress;

remove_filter('get_term', array($sitepress, 'get_term_adjust_id'), 1);
}

function wpgraphqlwpml_action_init()
{
if (!wpgraphqlwpml_is_graphql_request()) {
Expand Down Expand Up @@ -818,9 +830,16 @@ function wpgraphqlwpml_action_init()
10,
2
);
}

// Remove the adjust id filter during WPGraphQL requests
add_action(
'init_graphql_request',
'wpgraphqlwpml__remove_term_adjust_id_filter',
10,
0
);

add_action('graphql_init', 'wpgraphqlwpml_action_init');
}


add_action('graphql_init', 'wpgraphqlwpml_action_init');