Skip Navigation

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

Last updated by Waqar Ali 6 months, 3 weeks ago.

Assisted by: Waqar Ali.

Author Posts
June 3, 2024 at 6:59 pm

francescoS-56

Background of the issue:
I'm trying to get some posts using a custom API. When the plugin is active, I don't get any data. URL: hidden link

Symptoms:
I was expecting to see a list of posts with titles, links and thumbnails, but instead I got an empty array.

Questions:
Why am I not getting data when the WPML plugin is active?
How can I fix the custom API issue with WPML?

June 3, 2024 at 7:48 pm
June 4, 2024 at 8:53 am #15700512

Waqar Ali

Hi,

Your website seems to be down, but I'm currently performing some tests with this code on my test website.

Will share the findings, as soon as this testing completes.

Thank you for your patience.

regards,
Waqar

June 4, 2024 at 12:44 pm #15702087

Waqar Ali

I've tested your code on my test website and it works as expected, even with the String Translation plugin activated.

Looks like something specific to your website is involved. The website is still not accessible, so I'll wait to hear back from you, once the website is back online.

I'll also need your permission to download a clone/snapshot of the website to test it on a different server, in case it's needed.

June 4, 2024 at 1:40 pm #15702289

francescoS-56

Hello Waqar, the website is back online, please do check it out. If it's strictly needed then you can clone it.

June 6, 2024 at 8:35 am #15709876

Waqar Ali

Just wanted to let you know that I'm currently running some tests on your website's clone.

I'll share the findings with you once this testing is completed.

Thank you for being so patient.

June 6, 2024 at 1:09 pm #15711169

Waqar Ali

Thank you for waiting.

During testing on your website's clone, I was able to make this REST API endpoint work with the String Translation active, by changing the line in the 'get_author_posts' function from:


'author' => $author->ID,

To:


'author__in' => $author->ID,

I hope this helps and let me know how it goes.

June 6, 2024 at 1:57 pm #15711474

francescoS-56

Hi Waqar, that seems to fix the query thanks. Can you tell me what is interfiring with that method though? That could be the cause of the other issue I talk about, when I want to filter by author posts in the WordPress dashboard the query shows an empty page.

Screenshot from 2024-06-06 09-43-02.png
June 7, 2024 at 8:12 am #15714060

Waqar Ali

You're welcome and glad that it is working.

Since I can't reproduce this behavior on a clean test website, it has to do with some user role and capability changes added to your website by a third-party theme or plugin.

The main difference between the 'author' and 'author__in' parameters is that the first one works for a single user ID and the second one checks from multiple (array) user IDs.

WordPress doesn't out-of-the-box support multiple user role assignments, but membership and user roles and capabilities management plugins can include it. That is the only logical explanation I can't think of.