on my website I use two CPT (made with Toolset plugin) and I also use the WordPress default posts. The two CPT called Aktivitäten which is German for activities (slug is “aktivitat”) and the other is Bewertungen which is review (slug is “bewertung”). Between those I have a one-to-many relationship as one Aktivität can have several Bewertungen. I also have added a PHP-Code in my function.php which creates automatically a WordPress default post when a new Bewertung (= review) is created. Into the WordPress default post the title from the bewertung-post is copied. Just check my last review I created on my test site with the title “Test review 123”. You can find this under menu item “Reviews (Toolset)” as well as under “WordPress Posts”. In the WordPress default posts it is the second post, as the copy rutine always creates two posts.
My request is now that in the WordPress default post also the title (as clickable link) of the related parent post of the Bewertung is shown. This means I want to see there as a clickable link the“Test Aktivität 09.01.”, and when I click on it, it should bring me to this Aktivität (activity).
The reason why I am using also the WordPress default posts is because those posts can be commented and a comment directly triggers a message. And this is unfortunately not possible with Toolset posts.
Before looking into your solution too deeply, please be aware that you *can* have comments with custom posts.
When registering a post type you can add support for comments—with post types registered with Toolset you need to specify support for comments in the settings as shown in the screenshot—although how this works is a little odd, and is one of the strangest quirks of WordPress.
When you specify support for comments in a custom post type, you are only enabling a checkbox on individual CPT posts that determines whether comments on that post are possible or not.
There is no global option to have comments "turned on" for every post of a post type.
But you can add a little code snippet to easily enough enforce that on all posts of that type, like this, for example:
function auto_enable_comments_for_custom_post_type($post_id, $post, $update) {
$custom_post_type = 'your_custom_post_type'; // Replace with your custom post type slug
if ($post->post_type != $custom_post_type) {
return;
}
// If this is a new post (not an update)
if (!$update) {
$args = [
'ID' => $post_id,
'comment_status' => 'open',
];
wp_update_post($args);
}
}
add_action('save_post', 'auto_enable_comments_for_custom_post_type', 10, 3);
So this would enable comments for your post type, which may make your solution involving generating standard posts redundant.
I activated comments in the CPT settings of CPT “bewertung” and then in the post query loop page (query loop is the WordPress term for Toolset view), when I added the comment block under post title a pop-up appeared which asked me if I want to activate comments for all posts. I did that and then I was able to add comments to posts in the frontend. I then created a new CPT “test” for which I also activated the comments function and then I added the code provided by you. On both view pages I am now able to add comments to posts, but the comments are either appear under all posts or they appear to the page.
This issue that a comment which I write under post XY does not appear after post XY I recognized already before opening this ticket. Because of this strange behavior I came to the idea to use the WordPress default posts because there I have this 1:1 relation between post and comment. Maybe I am doing something wrong and there is the possibility to get this functionality also for Toolset CPT. This would be nice because then I must not work with different post types. But if this is not possible I see the only solution by coping Toolset CPT posts to default WordPress post query loop to enable visitors to comment on reviews. What do you think?
I'm going to review the current setup and then perform some tests on my website, accordingly. Will share the findings, as soon as this testing completes.
Thank you for waiting, while I completed my testing around this.
Part 1: Showing correct comments attached to the current post:
During testing on my website, I noticed that when the 'Comments' block is added to a view's loop, it shows the comments from the current page where the view is being shown and not from the current post that is showing in the view's loop.
This means that the "4 responses to “Bewertungen”" that were repeating for all the posts of the view on the page 'Bewertungen' were from the current page and not from current posts.
The workaround to avoid that is to create a content template and add the 'Comments' block to that. After that, load that content template in the view loop.
I've created a content template named 'CT for comments in a view' on your website and then loaded it inside the view '3. View Bewertungen' (on the 'Bewertungen' page) and this has fixed the issue.
Part 2: Enabling comments for all the 'Bewertungen' posts:
I see that comments are still not turned on for all the existing 'Bewertungen' posts. You can use the following plugin to enable the comments for all the existing posts in this post type: https://wordpress.org/plugins/disable-comments/
Note: The code snippet that Nigel suggested earlier will make sure that comments are turned for any new 'Bewertungen' post that you'll add in the future.