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 2 replies, has 2 voices.

Last updated by andreaF-47 2 weeks, 4 days ago.

Assigned support staff: Yvette.

Author Posts
September 27, 2019 at 5:31 pm #4656141

andreaF-47

Hello,
I'm trying to get WP_Query results sorted by "date" but something goes wrong.

This is the query:

$testimonials_args = array(
	'orderby' => array( 'date' => 'DESC' ),
	'post_type' => 'testimonials',
	'post_status' => 'publish',
	'paged' => $paged,
	'posts_per_page' => $item_count
);
$testimonials = new WP_Query( $testimonials_args );

where "testimonials" is a custom post-type.

This is the query explained by $testimonials->request:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  JOIN wp_icl_translations wpml_translations ON wp_posts.ID = wpml_translations.element_id AND wpml_translations.element_type = CONCAT('post_', wp_posts.post_type)  WHERE 1=1  AND wp_posts.post_type = 'testimonials' AND ((wp_posts.post_status = 'publish')) AND ( ( ( wpml_translations.language_code = 'it' OR 0 ) AND wp_posts.post_type  IN ('post','page','attachment','wp_block','wpcf7_contact_form','portfolio','testimonials','spb-section' )  ) OR wp_posts.post_type  NOT  IN ('post','page','attachment','wp_block','wpcf7_contact_form','portfolio','testimonials','spb-section' )  )  ORDER BY wp_posts.post_title ASC LIMIT 0, 16

As you can see, the query has ordering by post_title instead of post_date.
I tried other kind of sorting but the result is always the same.

Thank you in advance
Matteo

September 27, 2019 at 10:47 pm #4656817

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Hello

I think the best way to approach this is to ask you to please recreate a simple example of this in the following sandbox site:

The site has been pre-loaded and configured with WPML modules. Please include you code for the post type in the functions.php of the active theme and then create a simple example that illustrates the problem you are encountering.

WordPress
One Click Login: hidden link
Username: demo
Password: D04kGghA91Ay

SFTP Credentials
Server: w5.wpsandbox.pro
Username: cobalt-puffin
Password: jvqM66zJt04SM1x1HTAP05qr

SSH Credentials
Hostname: w5.wpsandbox.pro
Username: cobalt-puffin
Password: jvqM66zJt04SM1x1HTAP05qr
Login:ssh -p 2222 cobalt-puffin@w5.wpsandbox.pro

Write back with steps on how to see this issue on the sandbox site.
I can then confirm it and see if I am able to get the appropriate resource to comment on what might be going wrong.

Thanks

September 28, 2019 at 1:04 am #4656989

andreaF-47

My issue is resolved now. Thank you!