Skip to content

Custom Relation Types

Register your own relationship types with ncr_register_relation_type().

Registration

php
add_action( 'init', function() {
    ncr_register_relation_type( [
        'name'            => 'recommended_by',
        'label'           => __( 'Recommended by', 'your-textdomain' ),
        'from'            => 'post',
        'to'              => 'post',
        'bidirectional'   => false,
        'max_connections' => 20,
    ] );
}, 20 );

Arguments

KeyTypeDescription
namestringUnique slug (e.g. recommended_by).
labelstringDisplay label in admin.
fromstringSource object type: post, user, or term.
tostringTarget object type: post, user, or term.
bidirectionalboolWhether the relationship is two-way.
max_connectionsintMax relations of this type from a single source.

Returns: true on success, WP_Error on failure (e.g. invalid types or duplicate name).

Listing types

php
$types = ncr_get_registered_relation_types();

Use the same type slug in ncr_add_relation, ncr_get_related, and WP_Query.

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