WPML Translating a term/taxonomy programmatically

Ok I found the solution. Actually taxonomy name on icl_translation table is stored with prefix called “tax_” which means taxonomy. The above code would work like this: $trid = $sitepress->get_element_trid($englist_term_id, “tax_taxonomy_name”); $sitepress->set_element_language_details($new_term_id, “tax_taxonomy_name”, $trid, $lang_code, $sitepress->get_default_language()); The difference is tax_ prefix. Cheers!

Cannot use object of type WP_Error as array

Well, it’s pretty clear, why this problem occurs. Let’s look at wp_insert_term documentation: Return Values (array|WP_Error) The Term ID and Term Taxonomy ID. (Example: array(‘term_id’=>12,’term_taxonomy_id’=>34)) As you can see, on success this function returns array. But… If any error occurs, it will return an object of WP_Error type. So… This Fatal Error occurs, because wp_insert_term … Read more

Created pages not showing up in ‘All Pages’ list

The problem was actually the pages having “no language” and WPML seems to hate this. So I just deleted all those pages and re-inserted them with the proper WPML language attributes: // (…) // Create the page $customPage[‘id’] = wp_insert_post( $pageParams ); // Check if WPML parameters are needed if (has_action(‘wpml_set_element_language_details’)) { // Set WPML … Read more

How can override a add_filter of a plugin?

Filters come with a priority parameter, the default is 10, so to override a function you need to increase the priority: add_filter( ‘wcml_switch_currency_exception’, ‘cart_switching_currency’, 99, 4 ); add_filter( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) More info in the add_filter Update: If removing a filter is not working you … Read more

Unable to display multiple post types in same query (WPML WP_Query)

I had this problem with querying on two custom post types, using WP_Query. I had no problem querying for one type or the other in the array, but not both at the same time. Did not work: $args = array( ‘post_type’ => array(‘custom_type_1′,’custom_type_2’), ‘posts_per_page’ => 4 ); Did work: $args = array( ‘post_type’ => array(‘custom_type_1’), … Read more