Skip Navigation

[Resolved] Bug when uploading an image when adding a custom post type

This thread is resolved. Here is a description of the problem and solution.

Problem:

Using relationship API function toolset_connect_posts() in custom codes.

Solution:

You can follow our document to setup the custom codes.

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

This support ticket is created 3 years 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by morganS-2 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2258471

So, some users have experienced an error while uploading an image: "An error occurred in the upload. Please try again later."

For weeks, we were confused because it was not easily replicable and thought it could be caching rules (which are disabled on this page now) or issues with credentials/permissions. Couldn't nail it to any one of those through rigorous testing.

Here's a server error we encountered in the process of investigating --

2022/01/04 17:18:44 [error] 27235#27235: *1596434 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught InvalidArgumentException: The parent must be a post ID or a WP_Post instance. in /www/electriccycleridercom_223/public/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/public_api/m2m.php:542
Stack trace:
#0 /www/electriccycleridercom_223/public/wp-content/themes/ecr/functions.php(443): toolset_connect_posts('dealer-listing', NULL, 8209)
#1 /www/electriccycleridercom_223/public/wp-includes/class-wp-hook.php(303): connect_listing_to_dealer(8209, Array)
#2 /www/electriccycleridercom_223/public/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#3 /www/electriccycleridercom_223/public/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#4 /www/electriccycleridercom_223/public/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(720): do_action('cred_submit_com...', 8209, Array)
#5 /www/electriccycleridercom_223/public/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(472)" while reading response header from upstream, client: 174.118.194.118, server: electriccyclerider.com, request: "POST /add-a-listing/?_tt=1641316610 HTTP/1.1", upstream: "<em><u>hidden link</u></em>:", host: "electriccyclerider.com:47086", referrer: "<em><u>hidden link</u></em>"

The stack trace led to line 443 on our functions.php file, which is the "toolset_connect_posts" line below. The whole function is:

/**
 *  Connect Listings to Dealer (Relationship) after listing post is submitted 
 */
add_action('cred_submit_complete', 'connect_listing_to_dealer',10,2);
function connect_listing_to_dealer($post_id, $form_data) {
    if (in_array($form_data['id'],array(1060,1303,3340,6718))) { // Add a Listing/affiliate Forms
		$author_id = get_post_field( 'post_author', $post_id );
		$dealerPost = get_author_dealer_post($author_id);
		toolset_connect_posts( 'dealer-listing', $dealerPost->ID, $post_id );
    }
}

Is this function (toolset_connect_posts) now deprecated? Or, is the "$dealerPost->ID" not setup correctly due to the "NULL" seen in the error log? We're establishing a relationship in this function due to some other custom work we've created in the site. I've included credentials if you'd like to poke around.

#2258853

Hello,

The function toolset_connect_posts() is a built-in function of Toolset Types plugin.

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
According to the debug logs you mentioned above, the problem is in your custom PHP function get_author_dealer_post(), it does not return the correct post ID value, and conducts the problem, I suggest you check it with the author of that custom PHP function get_author_dealer_post().

#2264991

Thanks