Okay let's look at the code here first:
add_action('manage_solution_post_custom_column', 'show_my_related_posts_column',6);
function show_my_related_posts_column($my_related_posts){
switch ($my_related_posts) {
case 'toolset_get_related_posts' :
$usages = toolset_get_related_posts(
$solution,
array(
'parent' => 'solution',
'intermediary' => 'solution-usage'
)
);
echo $usages;
break;
}
}
1. The $solution variable is undefined. It should be added as a parameter in the function call so you have access to the solution post ID in the callback, and you should add a 2 in the add_action call params to indicate you will pass 2 params to the callback:
add_action('manage_solution_post_custom_column', 'show_my_related_posts_column', 6, 2 );
function show_my_related_posts_column($my_related_posts, $solution){
2. The toolset_get_related_posts function requires more than two parameters. Here's a guide to the minimum requirements, in order:
- origin post id ( $solution )
- post relationship slug ( your-relationship-slug )
- role of the origin post ( 'parent', 'intermediary', or 'child', depending on the post relationship )
- limit (a positive integer number is required here, I usually use 1000000)
- page # ( usually 0 )
- array of arguments ( usually an empty array() )
- return type ( 'post_id' or 'post_object' )
- role to return ( usually 'child' or 'parent', infrequently 'intermediary')
Here's a code template you can use:
$usages = toolset_get_related_posts(
$solution,
'solution-usages-relationship-slug',
'parent',
1000000,
0,
array(),
'post_id',
'child'
);
You should replace solution-usages-relationship-slug with the actual slug of this post relationship. You can find that in Toolset > Relationships if you edit this post relationship. Then the next line down depends on the aliases in this post relationship. If "Solution" is the parent, use 'parent'. If "Solution" is the child, use 'child'. You can determine the aliases in the same edit post relationship screen. Check the checkbox to confirm you want to edit the relationship settings, and you will see the aliases listed. Don't make modifications, just note which is parent and which is child. The next three parameters you probably don't need to modify. Choose 'post_id' or 'post_object' for the next-to-last parameter, depending on what you want to retrieve. The final parameter is the opposite of what you chose for the 3rd parameter.
Now if you chose post_id, when you echo $usages you will probably see something like "Array" because the variable holds an array of post IDs. You should iterate over those using foreach to display each post title or link or whatever you want to show here.