This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by Bruno 3 years, 10 months ago.

Assigned support staff: Bruno.

Author Posts
October 5, 2015 at 5:50 pm #718222

Anastis Sourgoutsidis

In WPML 3.2.7, auto-adust IDs doesn't work as expected with tax_query parameters.
Example: Category 65 is the default, english category, while category 89 is the respective greece translation.
Querying as such:

$args = array(
	'post_type'        => 'post',
	'tax_query'        => array(
		array(
			'taxonomy' => 'category',
			'terms'    => 65
		),
	),
	'posts_per_page'   => 5,
);
$q = new WP_Query( $args );

produces the following object:

WP_Query Object
(
    [query_vars] => Array
        (
            [post_type] => post
            [tax_query] => Array
                (
                    [0] => Array
                        (
                            [taxonomy] => category
                            [terms] => 65
                        )

                )

            [posts_per_page] => 5
            [error] => 
            [m] => 
            [p] => 0
            [post_parent] => 
            [subpost] => 
            [subpost_id] => 
            [attachment] => 
            [attachment_id] => 0
            [name] => 
            [static] => 
            [pagename] => 
            [page_id] => 0
            [second] => 
            [minute] => 
            [hour] => 
            [day] => 0
            [monthnum] => 0
            [year] => 0
            [w] => 0
            [category_name] => %ce%bc%cf%8c%ce%b4%ce%b1
            [tag] => 
            [cat] => 89
            [tag_id] => 
            [author] => 
            [author_name] => 
            [feed] => 
            [tb] => 
            [paged] => 0
            [comments_popup] => 
            [meta_key] => 
            [meta_value] => 
            [preview] => 
            [s] => 
            [sentence] => 
            [fields] => 
            [menu_order] => 
            [category__in] => Array
                (
                )

            [category__not_in] => Array
                (
                )

            [category__and] => Array
                (
                )

            [post__in] => Array
                (
                )

            [post__not_in] => Array
                (
                )

            [tag__in] => Array
                (
                )

            [tag__not_in] => Array
                (
                )

            [tag__and] => Array
                (
                )

            [tag_slug__in] => Array
                (
                )

            [tag_slug__and] => Array
                (
                )

            [post_parent__in] => Array
                (
                )

            [post_parent__not_in] => Array
                (
                )

            [author__in] => Array
                (
                )

            [author__not_in] => Array
                (
                )

            [meta_query] => Array
                (
                )

            [ignore_sticky_posts] => 
            [suppress_filters] => 
            [cache_results] => 1
            [update_post_term_cache] => 1
            [update_post_meta_cache] => 1
            [nopaging] => 
            [comments_per_page] => 50
            [no_found_rows] => 
            [order] => DESC
        )

    [tax_query] => WP_Tax_Query Object
        (
            [queries] => Array
                (
                    [0] => Array
                        (
                            [taxonomy] => category
                            [terms] => Array
                                (
                                    [0] => 65
                                )

                            [field] => term_id
                            [operator] => IN
                            [include_children] => 1
                        )

                )

            [relation] => AND
            [table_aliases:protected] => Array
                (
                    [0] => wpprv_92_term_relationships
                )

            [queried_terms] => Array
                (
                    [category] => Array
                        (
                            [terms] => Array
                                (
                                    [0] => 65
                                )

                            [field] => term_id
                        )

                )

            [primary_table] => wpprv_92_posts
            [primary_id_column] => ID
        )

    [meta_query] => WP_Meta_Query Object
        (
            [queries] => Array
                (
                )

            [relation] => 
            [meta_table] => 
            [meta_id_column] => 
            [primary_table] => 
            [primary_id_column] => 
            [table_aliases:protected] => Array
                (
                )

            [clauses:protected] => Array
                (
                )

            [has_or_relation:protected] => 
        )

    [date_query] => 
    [post_count] => 0
    [current_post] => -1
    [in_the_loop] => 
    [comment_count] => 0
    [current_comment] => -1
    [found_posts] => 0
    [max_num_pages] => 0
    [max_num_comment_pages] => 0
    [is_single] => 
    [is_preview] => 
    [is_page] => 
    [is_archive] => 1
    [is_date] => 
    [is_year] => 
    [is_month] => 
    [is_day] => 
    [is_time] => 
    [is_author] => 
    [is_category] => 1
    [is_tag] => 
    [is_tax] => 
    [is_search] => 
    [is_feed] => 
    [is_comment_feed] => 
    [is_trackback] => 
    [is_home] => 
    [is_404] => 
    [is_comments_popup] => 
    [is_paged] => 
    [is_admin] => 
    [is_attachment] => 
    [is_singular] => 
    [is_robots] => 
    [is_posts_page] => 
    [is_post_type_archive] => 
    [query_vars_hash:private] => c0b603ec58dbddd8dab72623fd75f893
    [query_vars_changed:private] => 1
    [thumbnails_cached] => 
    [stopwords:private] => 
    [compat_fields:private] => Array
        (
            [0] => query_vars_hash
            [1] => query_vars_changed
        )

    [compat_methods:private] => Array
        (
            [0] => init_query_flags
            [1] => parse_tax_query
        )

    [query] => Array
        (
            [post_type] => post
            [tax_query] => Array
                (
                    [0] => Array
                        (
                            [taxonomy] => category
                            [terms] => 65
                        )

                )

            [posts_per_page] => 5
        )

    [request] => SELECT SQL_CALC_FOUND_ROWS  wpprv_92_posts.ID FROM wpprv_92_posts  INNER JOIN wpprv_92_term_relationships ON (wpprv_92_posts.ID = wpprv_92_term_relationships.object_id) JOIN wpprv_92_icl_translations t
							ON wpprv_92_posts.ID = t.element_id
								AND t.element_type = CONCAT('post_', wpprv_92_posts.post_type)  WHERE 1=1  AND ( 
  wpprv_92_term_relationships.term_taxonomy_id IN (65)
) AND wpprv_92_posts.post_type = 'post' AND (wpprv_92_posts.post_status = 'publish' OR wpprv_92_posts.post_status = 'private') AND ( ( t.language_code = 'el' AND wpprv_92_posts.post_type  IN ('post','page' )  ) OR wpprv_92_posts.post_type  NOT  IN ('post','page' )  ) GROUP BY wpprv_92_posts.ID ORDER BY wpprv_92_posts.menu_order, wpprv_92_posts.post_date DESC LIMIT 0, 5
    [posts] => Array
        (
        )

)

It can be seen that 'category_name' and 'cat' are set properly, however on the final SQL query, ultimately the id 65 is used.

Setting 'suppress_filters' to true/false/1/0 does not have any effect.

October 6, 2015 at 9:51 pm #719207

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

You can use the wpml_object_id filter ( https://wpml.org/wpml-hook/wpml_object_id/ ).

Please, try this one:

$args = array(
    'post_type'        => 'post',
    'tax_query'        => array(
        array(
            'taxonomy' => 'category',
            'terms'    => (int) apply_filters( 'wpml_object_id', 65, 'category' )
        ),
    ),
    'posts_per_page'   => 5,
);
$q = new WP_Query( $args );

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Thank you.

October 7, 2015 at 10:25 am #719525

Anastis Sourgoutsidis

I am aware of the wpml_object_id filter.
However I thought the point of auto-adjust IDs is to avoid having to write wpml-specific code, therefore my previous post is more like a bug report, rather than a support request.

So, I'd like to know if it is indeed a bug and if it's going to be fixed in the (near) future.
If not, we'll need to change our themes appropriately.

Regards

October 7, 2015 at 3:57 pm #719860

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

The "Adjust IDs" option may not work in all parts of the code. The primary responsibility of "Adjust IDs" is work with the WordPress default functions that are used to display the pages, posts, tags and categories.

Example, when the posts or pages do not work with WPML, the "Adjust IDs" could try to resolve the problem.

However, for custom coding, it is recommended to use hooks. In the above example, the wpml_object_id works as expected, even in a custom loop.

Please let me know if I can help you with any other questions you might have.

Thank you.

The topic ‘[Closed] tax_query not handled by auto-adjust IDs’ is closed to new replies.