Hey there,
We are trying to connect Ninja form submissions (post type = nf_sub) with Toolset created post type named as Rule. But the nf_sub post type is not visible in the Toolset Type dashboard or relationship wizard area.
Is it possible to setup a relationship in between "nf_sub" and "rule" post type using code or Toolset?
We tried the toolset_connect_posts hook but this returns the "The relationship does not exist" error which is fair because we never created it.
So, I am wondering if we can achieve one of the following?
1. Create/register/establish a relationship between nf_sub and rule post type? (check image1.png)
2. Or if it's possible to make nf_sub visible in toolset type sections so we can use it just like standard custom post type?
Thanks for your help.
Hi,
Thank you for contacting us and I'd be happy to assist.
The Toolset's post relationships can be created only for the post types, which are set to be 'public'.
( ref: https://developer.wordpress.org/reference/functions/register_post_type/#parameters )
But the way the "Ninja Forms" plugin registers its post type 'nf_sub', it is not set to be 'public'.
On my test website, I was able to make it 'public' (and thus available for the relationships), using the following code:
function custom_nf_sub_post_type_args( $args, $post_type ) {
if ( $post_type == "nf_sub" ) {
$args['public'] = true;
}
return $args;
}
add_filter( 'register_post_type_args', 'custom_nf_sub_post_type_args', 20, 2 );
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
I hope this helps and please let me know if you need further assistance.
regards,
Waqar