Skip Navigation

[Resolved] Error with toolset_get_related_post()

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/Karachi (GMT+05:00)

This topic contains 10 replies, has 2 voices.

Last updated by Waqar 1 year ago.

Assisted by: Waqar.

Author
Posts
#2653747

Tell us what you are trying to do?
- Add field to a layout built by a previous developer.
- A custom post type needs a new field added, which I was able to do successfully. However, in the process, WP started throwing errors on the template, which makes me think it changed something somewhere else.
- I am moderately experienced as a WP dev, with no experience with Toolset.

Is there any documentation that you are following?
- https://toolset.com/documentation/legacy-features/toolset-layouts/
- https://toolset.com/?s=toolset_get_related_post+&lang=en

Is there a similar example that we can see?

Error Details
=============
An error of type E_ERROR was caused in line 246 of the file /home/dh_758u25/pce-test-retry.massart.edu/wp-content/plugins/layouts/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php. Error message: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in /home/dh_758u25/pce-test-retry.massart.edu/wp-content/plugins/layouts/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php:246
Stack trace:
#0 /home/dh_758u25/pce-test-retry.massart.edu/wp-content/plugins/layouts/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php(177): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->set_query_by_elements(Array, 'child')
#1 /home/dh_758u25/pce-test-retry.massart.edu/wp-content/plugins/layouts/vendor/toolset/toolset-common/inc/public_api/m2m.php(159): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->__construct('', 'catalog-to-sect...', Array)
#2 /home/dh_758u25/pce-test-retry.massart.edu/wp-content/plugins/pce-catalog-wp-plugin/pce-website.php(2624): toolset_get_related_post('', 'catalog-to-sect...', 'parent')
#3 /home/dh_758u25/pce-test-retry.massart.edu/wp-admin/includes/template.php(1443): pce_course_recommendation_meta_box(Object(WP_Post), Array)
#4 /home/dh_758u25/pce-test-retry.massart.edu/wp-admin/edit-form-advanced.php(711): do_meta_boxes(Object(WP_Screen), 'advanced', Object(WP_Post))
#5 /home/dh_758u25/pce-test-retry.massart.edu/wp-admin/post.php(206): require('/home/dh_758u25...')
#6 {main}
thrown

What is the link to your site?
- hidden link

#2653943

Hi,

Thank you for contacting us and I'd be happy to assist.

Is this error logged while you're visiting any specific page/section on the front end or the admin area? And is it also causing any lost functionality or unexpected results?

I'll recommend making sure that WordPress, active theme, and all plugins are updated to the latest versions.

In case the issue still persists, you're welcome to share temporary admin login details, along with the exact steps to see the error.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2654789

Hi Waqar:

> Is this error logged while you're visiting any specific page/section on the front end or the admin area?

Yes, hidden link. It doesn't seem to be on other pages? May need more testing. Not sure why just this page when others are constructed the same, but I don't fully understand what the function is pulling from.

> I'll recommend making sure that WordPress, active theme, and all plugins are updated to the latest versions.

WordPress is current. The theme is custom. All plugins are updated.

> In case the issue still persists, you're welcome to share temporary admin login details, along with the exact steps to see the error.

Will be following post.

> …making a complete backup copy is recommended before sharing the access details.

Done.

#2654799

I can't select private or public. Please make the next reply private and I will post credentials.

#2655079

Thank you for sharing this update and I've set your next reply as private again.

#2655661

Thank you for sharing the access details, but I keep getting the incorrect password message.

Can you please check the password again? I'm setting the next reply as private.

#2655981

I reset the password for the `toolset-dev` account to the password specified above, then tested it by logging in.

You should be good.

#2656915

I was able to access the website's admin area, thank you.

While I can see the issue with the relationship edit section on the post-edit screen, I couldn't reproduce this on my test website. Looks like something specific to your website is involved.

Do I have your permission to download the clone/snapshot of the website? This will help in troubleshooting this on a different server, without affecting the actual website.

#2657051

Sure that's fine. This is a test server for development of production, so if it blow up, it's not a concern.

#2658711

Thank you for the permission and I have downloaded the website's clone.

I had unusually busy forum queue over the weekend, but I'll get back to you with a detailed update, within the next few hours.

Thank you for your patience.

#2658893

Thank you for waiting.

During troubleshooting, I noticed that the issue with the relationship edit section would get fixed, when the custom plugin 'PCE Website Plugin' was deactivated.

Although, custom code troubleshooting is beyond the scope of support that we provide over the forum, we do our best to guide in the right direction whenever possible.

At the line #2642 of the plugin's file at: /wp-content/plugins/pce-catalog-wp-plugin/pce-website.php, you'll find this code:


if ( ! $recommendation2_selected ) {

Because there is no empty check for the value '$recommendation2_section_id', when it is empty and then used in the function 'toolset_get_related_post' next, it results in the error:
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post )

By including an empty check in that conditional statement, this error can be fixed:


if ( (! $recommendation2_selected) && (!empty($recommendation2_section_id)) ) {

#2659801

Thank you for the assistance. I will look at that function and see if it can be removed, or I will implement your suggested check.