Skip Navigation

[Resolved] Error: Call to undefined function toolset_connect_posts()

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by rafaelM-3 2 years, 10 months ago.

Author
Posts
#2595969

Good morning.

I am trying to create and link custom post with relationships, all created with Tooset, by php. The creation of the custom post is done correctly but, when creating the links, I get the error "Call to undefined function toolset_connect_posts()".

I'm running all of this through the Code Snippets plugin in run once mode.

Any idea why it doesn't recognize the toolset_connect_posts function?

Thank you.

Regards.

#2596057

Hi again.

I have managed to use the toolset_connect_posts function by running the code after all the plugins have been loaded. Now, I get the following error: "Uncaught InvalidArgumentException: The element to connect with doesn't belong to the relationship definition provided"

I am trying to link a custom post of type, called comarca, with a custom type, called municipio, through a relationship named 'comarca-municipio' (1:N) with the following code:

toolset_connect_posts( 'comarca-municipio', $municipio_id, $comarca_id );

, where $municipio_id is the id of the post type municipio and $comarca_id is the id of the post type comarca.

What am I doing wrong?

Thank you.

Regards.

#2596219

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hola Rafael

It looks like you simply have the arguments in the wrong order (the error indicates that the values of either—or both—of $municipio_id or $comarca_id don't correspond to the expected post types for the parent and child posts in the relationship).

Try swapping them, like so:

toolset_connect_posts( 'comarca-municipio', $comarca_id, $municipio_id );
#2596319

My issue is resolved now.

I can't believe it was that nonsense.

Thanks a lot.