[Resolved] Are all toolset_get_related_posts required?
This thread is resolved. Here is a description of the problem and solution.
Problem:
The toolset_get_related_posts function of the API has a lot of possible arguments, are they all required?
Solution:
The first 3 are required for one-2-many relationships.
For m2m relationships all 8 arguments are required. (We plan to update this to make it easier to pass only certain arguments and leave others as default.)
I'm reviewing the documentation at https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/ and it's unclear if all arguments are required. I'm writing a custom shortcode that needs to pull all related posts but I do not require pagination or any limit on the number of records returned, so I prefer not to set a limit or offset. Any clarification on this would be helpful. Thanks.
For one-2-many relationships it is enough to provide the first 3 arguments of toolset_get_related_posts. Default values will be used for the remaining arguments.
For many-to-many relationships you will need to provide the 8th argument, and because of the way you pass the arguments you must therefore pass at least the first 8. (There is also a bug where you cannot pass "-1" for limit to indicate "unlimited", you will need to pass an arbitrarily high number instead in this case.)
We already have an internal ticket about improving this so that the arguments are passed as an array of key-value pairs so that you only need to pass the arguments that you need to specify.
Thanks, that's helpful, and I think I've figured out what is wrong. So I have the following code and I've confirmed that $a['productid'] is defined properly but my php function chokes when it goes to define $reviews. I don't get an error message - the page simply doesn't load. Removing the 'post_object' line seems to fix the problem, I'm guessing because the items in the array are out of order by not including what would otherwise be between 'parent' and 'post_object'.
It will be nice when they switch to key-value pairs.
Product-Listing is the parent post and Product-Review is the child post (many reviews to one product). I have entered and published a review and verified it is connected to a product, yet it's not returning any results. Just thought I'd check in and make sure I'm setting the attributes properly for the toolset_get_related_posts() function.
That did the trick. It is a migrated relationship but the specific post connection was created after the migration. I updated the code as per below and now it works!