Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem: tax_query in WP_Query does not display results

Solution: From the provided query, the client was using post_id on the query, we recommend to use the wpml_object_id hook to get the ids properly while using WPML

Relevant Documentation:

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.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Kim Gamez 1 year, 3 months ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
April 29, 2019 at 1:51 pm #3704045

Kim Gamez

I am trying to: see custom query on translated page

Link to a page where the issue can be seen: developing locally

I expected to see: the post results

Instead, I got: No results Found

April 29, 2019 at 1:56 pm #3704067

Kim Gamez

Displays in default language but not in translated language.

$post_id = get_the_id();
$args = array(
	'post_type' => 'vendor',
	'post_status' => 'publish',
	'post__not_in' => array( $post_id ),
	'posts_per_page' => $limit,
	'tax_query' => array(
        array(
            'taxonomy' => 'vendor_category',
            'field'    => 'term_id',
            'terms'    => wp_get_post_terms( $post_id, 'vendor_category', array( 'fields' => 'ids' ) ),
        ),
    ),
	'meta_query' => array(
        array(
            'key'     => 'subscription_level',
            'value'   => 3,
            'compare' => 'in',
        ),
    )
);

$query = new WP_Query($args);
April 30, 2019 at 4:40 am #3707857

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Thank you for contacting WPML support. I'd be happy to assist you further on this issue.

You are using post_id on the query, which may not be returning the correct id on the translated language creating issues.

Could you please use the wpml_object_id hook to get the translated ID and let me know if this helps?
+ https://wpml.org/wpml-hook/wpml_object_id/
+ https://wpml.org/documentation/support/debugging-theme-compatibility/#issue-usage-of-the-wrong-id-value-for-the-wp_query-args-tax_query-field-arguments

Look forward to your reply.

Thanks

April 30, 2019 at 7:58 pm #3714703

Kim Gamez

Shekahar,
I am not sure exactly what I did but things seem to be working as I expect them to. weird

May 2, 2019 at 5:29 am #3721901

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Glad to know it worked, You can mark the ticket as resolved now.

Look forward to your reply.

Thanks

May 3, 2019 at 5:27 pm #3737271

Kim Gamez

My issue is resolved now. Thank you!