The code you are using above looks like it is just copied and pasted from the examples in the documentation without being updated for your site, and the orderby argument hasn't been changed to order by date, so I wouldn't expect it to give you meaningful results.
To be able to help you with the code, can you clarify what are the post types in the relationship, what kind of relationship is it, what is the slug of the relationship, and what kind of posts are you trying to display (i.e. which of the post types is the related post type you want to output)?
Probably this would help you to understand my issue better hidden link hidden link
No matter what id i use here, it always shows the same result. You can try with any id and see it showing the same result.
I have displayed the query on the page, so that you get an idea of the issues I am facing.
In your previous reply you mentioned above "looks like it is just copied and pasted from the examples".
Of Course it's the same. Shouldn't the parameters be the same?. The parameter values are different in my case.
For example you can see the relationship slug is different
In order to troubleshoot this on my test website and suggest the best way forward, I'll need to see exactly how these post types and the relationship are setup in the admin area. Please also share some information about how and where are you using this code snippet.
Note: The two links from your last message are showing "404 not found" page.
I've set your next reply as private and and please make a complete backup copy, before sharing the temporary admin access details.
Hello,
Our developper gave you the access to WP admin yesterday. Could you tell me if you found anything? Do you need anything from our side?
I'm sorry but it's really urgent. We were supposed to launch the website 4 weeks ago and we are stuck because of this ordering. It's really important.
1. I've changed "posts_per_page" to "-1" as I needed all the related posts and not just 1.
2. I've changed "role" to "parent" as posts is the parent in the relationship.
3. The parameters "orderby" and "order" are optional in this case, since by default results are ordered by date in descending order.
( ref: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters )
4. On your website, the "Post Types Order" plugins is active too. Plugins like these can override the posts order in WordPress query results globally. If you notice incorrect ordering, test with all extra plugins disabled.
If the issue still persists, with all extra plugins disabled and a default theme like Twenty Twenty, I'll need a clone/snapshot of the website, so that this can be investigated on a different server.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )
During troubleshooting, I noticed that there were about 6 posts that were set as "sticky" and by default, the WordPress Query class appends the sticky posts at the start of the resutls.
( ref: https://developer.wordpress.org/reference/classes/wp_query/ )
In your query arguments, you can set the "ignore_sticky_posts" to true, to ignore the sticky posts:
I've checked your template file and noticed that the "role" was still set to "child".
When I changed it to "parent", the query started working, as expected.
Example:
Front-end:
yourwebsite.com/test-to-del/?search_id=5359
( screenshot: hidden link )
Author "Danuta Maria Hübner" ( ID:5359 ) with only one related post:
yourwebsite.com/wp-admin/post.php?post=5359&action=edit
( screenshot: hidden link )