Skip to content

Fluent API

A chainable, IDE-friendly wrapper around the relationship API. Entry point: naticore().

Best for post-to-post relations in theme or plugin code where you prefer a fluent style over function calls.


Entry point

php
naticore();

Returns a NATICORE_Fluent_API instance. Chain methods and end with create(), get(), exists(), or remove().


Methods

MethodArgumentsReturnsPurpose
from( $post_id )int$thisSet source post ID
to( $post_id )int$thisSet target post ID
type( $type )string$thisSet relationship type (default related_to)
direction( $direction )string$thisSet direction (optional)
create()int|WP_ErrorCreate the relationship
get( $args = [] )arrayarrayGet related posts (uses from + type)
exists()bool|WP_ErrorCheck if relationship exists
remove()bool|WP_ErrorRemove the relationship

After create(), get(), exists(), or remove(), internal state is reset.


Examples

Create a relationship:

php
$result = naticore()
	->from( 123 )
	->to( 456 )
	->type( 'related_to' )
	->create();

if ( is_wp_error( $result ) ) {
	// Handle error
} else {
	// $result is the relation ID
}

Get related posts:

php
$related = naticore()
	->from( get_the_ID() )
	->type( 'related_to' )
	->get( [ 'limit' => 10 ] );
// $related is array of post IDs or objects (same as ncr_get_related)

Check if related:

php
$exists = naticore()
	->from( 123 )
	->to( 456 )
	->type( 'related_to' )
	->exists();
// true or false

Remove relationship:

php
naticore()
	->from( 123 )
	->to( 456 )
	->type( 'related_to' )
	->remove();

Scope

The fluent API uses the same backend as ncr_add_relation / ncr_get_related / etc. It is currently oriented to post-to-post relations (from_id and to_id as posts). For user or term relations, use the PHP API directly.


See also

Schema stable from 1.x onward. Backward compatibility guaranteed.