Hello.
1. Why doesn't it work?
2. How can I use toolset functions like "toolset_get_related_posts" in functions.php?
3. If I use it like in the screen 3 toolset_get_related_posts return empty array, but without error!
ps: If I use it in post template like single-custom-type-slug.php -- all works fine.
Hello, assuming the Toolset Types plugin is active and your site uses the new post relationships system (if the site was created using Types 3.0+, you are using the new post relationships system), this is probably a timing issue where the post relationships API function is called before Toolset is completely loaded. I use toolset_get_related_posts in functions.php quite often, but usually the function is called inside another hook or shortcode definition. The developers suggest using the post relationships API no sooner than init with a priority of 15 or higher:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#remarks
You may need to delay your code with an add_action hook, or in some other hook. Many examples here on the site use toolset_get_related_posts in shortcode definitions, or in callbacks for Forms API functions like cred_submit_complete, or in Views filter APIs like wpv_filter_query, etc:
https://toolset.com/forums/topic/next-and-previous-sibling-posts-in-a-one-to-many-post-relationship/
https://toolset.com/forums/topic/difference-between-wp_toolset_associations-and-wp_toolset_associations_old/
https://toolset.com/forums/topic/table-with-child-posts
https://toolset.com/forums/topic/repeatable-field-groups-form/
My issue is resolved now. Thank you!