{"action":"created","issue":{"url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/468","labels_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/468/labels{/name}","comments_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/468/comments","events_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/468/events","html_url":"https://github.com/scribu/wp-posts-to-posts/issues/468","id":50218954,"number":468,"title":"Listing related post types (schema not actual posts)","user":{"login":"unstoppablecarl","id":913047,"avatar_url":"https://avatars.githubusercontent.com/u/913047?v=3","gravatar_id":"","url":"https://api.github.com/users/unstoppablecarl","html_url":"https://github.com/unstoppablecarl","followers_url":"https://api.github.com/users/unstoppablecarl/followers","following_url":"https://api.github.com/users/unstoppablecarl/following{/other_user}","gists_url":"https://api.github.com/users/unstoppablecarl/gists{/gist_id}","starred_url":"https://api.github.com/users/unstoppablecarl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unstoppablecarl/subscriptions","organizations_url":"https://api.github.com/users/unstoppablecarl/orgs","repos_url":"https://api.github.com/users/unstoppablecarl/repos","events_url":"https://api.github.com/users/unstoppablecarl/events{/privacy}","received_events_url":"https://api.github.com/users/unstoppablecarl/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/scribu/wp-posts-to-posts/labels/question","name":"question","color":"e102d8"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-11-26T19:37:26Z","updated_at":"2015-01-28T16:15:44Z","closed_at":"2014-11-26T20:22:24Z","body":"Is there a better way to do this? \r\n\r\n```php\r\n<?php\r\n    function getRelatedPostTypes($postType){\r\n        $connections = P2P_Connection_Type_Factory::get_all_instances();\r\n        $related = [];\r\n        foreach($connections as $connection){\r\n            $fromPostType = $connection->side['from']->query_vars['post_type'][0];\r\n            if($fromPostType === $postType){\r\n                $related[] = $connection->side['to']->query_vars['post_type'][0];\r\n            }\r\n        }\r\n        return $related;\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/comments/71862705","html_url":"https://github.com/scribu/wp-posts-to-posts/issues/468#issuecomment-71862705","issue_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/468","id":71862705,"user":{"login":"MoiseScalzo","id":7465059,"avatar_url":"https://avatars.githubusercontent.com/u/7465059?v=3","gravatar_id":"","url":"https://api.github.com/users/MoiseScalzo","html_url":"https://github.com/MoiseScalzo","followers_url":"https://api.github.com/users/MoiseScalzo/followers","following_url":"https://api.github.com/users/MoiseScalzo/following{/other_user}","gists_url":"https://api.github.com/users/MoiseScalzo/gists{/gist_id}","starred_url":"https://api.github.com/users/MoiseScalzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MoiseScalzo/subscriptions","organizations_url":"https://api.github.com/users/MoiseScalzo/orgs","repos_url":"https://api.github.com/users/MoiseScalzo/repos","events_url":"https://api.github.com/users/MoiseScalzo/events{/privacy}","received_events_url":"https://api.github.com/users/MoiseScalzo/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T16:15:44Z","updated_at":"2015-01-28T16:15:44Z","body":"I solved with a custom query:\r\n<pre>\r\nfunction get_related_post_type($postID) {\r\n\r\n\tglobal $wpdb;\r\n\r\n\t$query = \"SELECT *\r\n\t\t\tFROM `cdm_wp_p2p`\r\n\t\t\tWHERE `cdm_wp_p2p`.`p2p_from` = '$postID'\";\r\n\r\n\t$reults = $wpdb->get_results($query);\r\n\r\n\t$related     = [ ];\r\n\r\n\tforeach ( $reults as $connection ) {\r\n\r\n\t\t$to = $connection->p2p_to;\r\n\t\t$related[] = get_post_type($to);\r\n\r\n\t}\r\n\r\n\t$related = array_unique($related);\r\n\t$related = array_filter($related);\r\n\r\n\treturn $related;\r\n\r\n}\r\n</pre>\r\n\r\nI have to do some tests, but it seems to work"}}