I'm getting 404 error when trying toaccess wp admin. error logs shows the following:
PHP Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in ../wp-content/plugins/types/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php:246
Stack trace:
#0 ../wp-content/plugins/types/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php(177): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->set_query_by_elements(Array, 'child')
#1 ../wp-content/plugins/types/vendor/toolset/toolset-common/inc/public_api/m2m.php(159): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->__construct(NULL, Array, Array)
#2 ../wp-content/themes/vernisandbowling/lib/bws-print-pdf.php(43): toolset_get_related_post(NULL, Array)
#3 ../wp-includes/class-wp-hook.php(309): {closure}(NULL)
#4 ../wp-includes/plugin.php(191): WP_Hook->apply_filters(NULL, Array)
#5 in ../wp-content/plugins/types/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php on line 246
Hello,
In the PHP debug logs you provided above, there is one line:
/wp-content/themes/vernisandbowling/lib/bws-print-pdf.php(43): toolset_get_related_post(NULL, Array)
toolset_get_related_post() function is a Toolset PHP function.
Are you using custom PHP codes toolset_get_related_post() in your theme file "themes/vernisandbowling/lib/bws-print-pdf.php"?
Please check above theme file "themes/vernisandbowling/lib/bws-print-pdf.php", line 43, and follow our document to setup the parameters:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Arguments
$post - WP_Post|int Post whose related post should be returned
You need make sure the first parameter $post value is an valid post ID or WordPress post object.
Hi Luo Yang,
Yes I am using custom PHP in the theme file. This is not the only page that uses the toolset_get_related_post() functiion. Here is the code from line 43 of bws-print-pdf.php
global $wp_query;
$postid = $wp_query->post->ID;
$my_content = '';
if ( function_exists( 'wpcf_pr_post_get_belongs' ) )
$parent_location = toolset_get_related_post( $postid, array( 'locations', 'attorney' ) );
if ( ! empty( $parent_location ) ) {
Other page template that I have this toolset_get_related_post() functiion in:
sIngle-verdict-disposition.php
global $wp_query;
$postid = $wp_query->post->ID;
$parent = wpcf_pr_post_get_belongs(get_the_ID(), 'locations');
$parent_verdict = toolset_get_related_post( $postid, array( 'locations', 'verdict-disposition' ) );
single-career-opportunity.php
global $wp_query;
$postid = $wp_query->post->ID;
$parent_career = toolset_get_related_post( $postid, array( 'locations', 'career-opportunity' ) );
single-attorney.php
global $wp_query;
$postid = $wp_query->post->ID;
$parent_location = toolset_get_related_post( $postid, array( 'locations', 'attorney' ) );
Hi Luo Yang,
I was able to get back into the admin dashboard after changing the name of the htaccess file. It allowed my access to the login page again, then I went in and saved the permalink settings again to create another htaccess file.
I'll just need your help in verifying the code used in the template files. Is anything wrong with the php code I shared with you?
Please check my above answer:
https://toolset.com/forums/topic/php-fatal-errors-in-log/#post-2438529
You need make sure the first parameter $post value is an valid post ID or WordPress post object.
In your custom PHP codes, you are using below codes:
global $wp_query;
$postid = $wp_query->post->ID;
You can print the $postid value, like this:
echo $postid;
Check if it does output an valid post ID.
Hope it is clear.
Yes it returns the correct post id #.
What else can I do to fix the error?
When it outputs the correct post ID, it won't conduct the PHP error.
When it outputs wrong post ID value, it will conduct the PHP error.
So you will find out where and when it trigger the PHP error, then check the post ID value.
Hope it is clear.
I am not exactly sure where and when the error is triggered. It does not look like the error_log file is updated instantly.
For example, the actual current date is 8/16/22 EST, but in the log file, the most recent error has the date of 17-Aug-2022 2:31:30 UTC
The "bws-print-pdf.php" file is for the plugin (hidden link)
I don't know if the error is triggered when the pdf is generated.
Is this "bws-print-pdf.php" the only file that's causing the error is the log?
Should I use another code other than the code below to get the post id?
global $wp_query;
$postid = $wp_query->post->ID;
Also, I have the same exact code in other page template files, but those pages are not showing up in the error.
According to our support policy, we don't provide other plugin support or custom codes support:
https://toolset.com/toolset-support-policy/
And in your case, it seems your custom PHP codes can not get correct post ID, and conducts the PHP error.
You can valid the post ID value before passing it to Toolset function, for example:
replace these lines in theme file bws-print-pdf.php, from:
$postid = $wp_query->post->ID;
$my_content = '';
if ( function_exists( 'wpcf_pr_post_get_belongs' ) )
To:
$postid = get_the_ID();
$my_content = '';
if ( $postid && function_exists( 'wpcf_pr_post_get_belongs' ) )
More help:
https://developer.wordpress.org/reference/functions/get_the_ID
Thanks Luo Yang!
It seems like that solved it. I haven't seen any new errors since making this change to the code.
I appreciate your help