Post Connector has a Developer API that includes the functions listed on this page. These functions won’t be removed in future updates, so they can safely be used in e.g. plugins and themes.

get_children
Since 1.5.0
This function is used to fetch childs of a parent post. Function returns all linked childs in an array, the array will contain default WordPress posts. Child posts will be fetched by post type slug and parent id, default WordPress arguments can be used in the $args variable.

[php]Post_Connector::API()->get_children( $post_connector_slug, $parent_id, $args );[/php]

get_first_child
Since 1.0.0
This function is used to fetch the first children of a parent post. The first child post will be fetched by post type slug and parent id. Function returns a default WordPress post.

[php]Post_Connector::API()->get_first_child( $post_connector_slug, $parent_id );[/php]

get_parents
Since 1.0.0
This function is used to fetch the parents of a child post. Function returns all linked parents in an array, the array will contain default WordPress posts. Parents posts will be fetched by post type slug and child id.

[php]Post_Connector::API()->get_parents( $post_connector_slug, $child_id );[/php]

delete_link
Since 1.0.0
This function is used to delete a link between parent and child post by the link ID. Note that this will not delete the post type link.

[php]Post_Connector::API()->delete_link( $link_id );[/php]

delete_post_type_link
Since 1.0.0
This function is used to delete a connection by the connection ID. Note that this will also delete all created links between posts using this post type link. This method will be renamed in the future to ‘delete_connection’, of course backwards compatibility will be maintained.

[php]Post_Connector::API()->delete_post_type_link( $ptl_id );[/php]

add_link
Since 1.0.0
This function is used to create a link between two posts based on the post type link ID, parent post ID and child post ID. Function will return the newly created link ID.

[php]Post_Connector::API()->add_link( $pt_link_id, $parent_id, $child_id );[/php]

add_link_by_slug
Since 1.2.2
This function is used to create a link between two posts based on the post type slug, parent post ID and child post ID. Function will return the newly created link ID.

[php]Post_Connector::API()->add_link_by_slug( $post_connector_slug, $parent_id, $child_id );[/php]

add_connection
Since 1.5.0
This function is used to create a post type link between two post types.
The following parameters should be passed when create a post type link:
Slug (string) – The new slug of the PTL
Title (string) – The new title of the PTL
Parent (string) – The parent post type id
Child (string) – The child post type id
Sortable (int) – Wether the item is sortable. 1 = yes, 0 = no.
Add new (int) – Wether the user can add and link new items. 1 = yes, 0 = no.
Add existing (int) – Wether the user can link existing items. 1 = yes, 0 = no.
After post display children – Display child posts automatically on post. 1 = yes, 0 = no.
After post display parents – Display parent posts automatically on post. 1 = yes, 0 = no.
Backwards Linking – Set to 1 if you want to allow backwards linking. 1 = enabled, 0 = disabled.

The function will return a SP_Connection object.

[php]Post_Connector::API()->add_connection( $slug, $title, $parent, $child, $sortable, $add_new, $add_existing, $after_post_display_children, $after_post_display_parents, $backwards_linking );[/php]

has_child
Since 1.3.0
This function is used to check if a parent post has at least one child.
$post_connector_slug – The connection slug.
$parent_id – ID of the post you want to check.

This function returns a boolean (true or false).

[php]Post_Connector::API()->has_child( $post_connector_slug, $parent_id );[/php]