Tell us what you are trying to do?
I am writing a custom filter to work with contactform7 that displays a selection field for the dates on which a certain presentation is given. It works fine on the front end.
However, when I try to access this particular form on the back end WordPress is reporting a critical error. The error log gives this error:
Backend fatal error: PHP Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in /home/deb96406/domains/autismedigitaal.nl/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php:246\nStack trace:\n#0 /home/deb96406/domains/autismedigitaal.nl/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php(177): OTGS\\Toolset\\Common\\Interop\\Commands\\RelatedPosts->set_query_by_elements(Array, 'child')\n#1 /home/deb96406/domains/autismedigitaal.nl/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/public_api/m2m.php(110): OTGS\\Toolset\\Common\\Interop\\Commands\\RelatedPosts->__construct(false, 'agenda-presenta...', Array)\n#2 /home/deb96406/domains/autismedigitaal.nl/public_html/wp-content/themes/behteme-stichting/functions.php(29): toolset_get_related_posts(false, 'agenda-presenta...', Array)\n#3 /home/ in /home/deb96406/domains/autismedigitaal.nl/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php on line 246\n, referer: hidden link
Here is my code:
function pine_dynamic_select_field_values ( $scanned_tag, $replace ) {
if ( $scanned_tag['name'] != 'datums' )
return $scanned_tag;
$presentatie_id = get_the_ID();
$relationship_slug = 'agenda-presentatie';
$rows = toolset_get_related_posts(
// get posts related to this one
$presentatie_id,
// Relationship between the posts
array( 'agenda', 'presentatie' ),
// Additional arguments
[
// Get posts where $writer is the parent in given relationship.
// This is mandatory because we're passing just a single $writer post as the first parameter.
'query_by_role' => 'child',
// pagination
'limit' => $posts_per_page,
'offset' => ( $current_page - 1 ) * $post_per_page,
'role_to_return' => 'parent',
'return' => 'post_id'
]
);
if ( ! $rows )
return $scanned_tag;
foreach ( $rows as $row ) {
$datums = get_post_meta( $row, "wpcf-datum", false );
foreach ( $datums as $datum ) {
setlocale(LC_TIME, 'nl_NL');
$datum = strftime("%d %B %Y", $datum);
$scanned_tag['raw_values'][] = $datum . '|' . $datum;
}
}
$pipes = new WPCF7_Pipes($scanned_tag['raw_values']);
$scanned_tag['values'] = $pipes->collect_befores();
$scanned_tag['pipes'] = $pipes;
return $scanned_tag;
}
Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
hidden link
What is the link to your site?
hidden link (not the first select field, but the one at the bottom of the form) but the error is on the backend