admin管理员组

文章数量:1297049

I have a page with a shortcode that displays information from the database. I have set it up to allow comments on the page. The problem I am having is when I click Submit Comment, I get the following message:

Notice: Undefined index: id in events.php on line 989

This line gets the id from the link the user clicks to get to this page, which works fine. Is there a way to pass this id through the comments.php page to make sure the page loads fine? Here is the comments.php code:

if (have_comments()) {
    wp_list_comments('');
}

$comments_args = array(
    'label_submit' => 'Submit Comment',
    'title_reply' => 'Post a Comment',
    'comment_notes_after' => ''
);
comment_form($comments_args);

EDIT

What the problem is is that have a page that displays different links to events on it. When I click the link, it opens the record associated with the link, which can be different each time.

So, what I need to have happen, is to have comments associated with the record displayed on that page.

I have a page with a shortcode that displays information from the database. I have set it up to allow comments on the page. The problem I am having is when I click Submit Comment, I get the following message:

Notice: Undefined index: id in events.php on line 989

This line gets the id from the link the user clicks to get to this page, which works fine. Is there a way to pass this id through the comments.php page to make sure the page loads fine? Here is the comments.php code:

if (have_comments()) {
    wp_list_comments('');
}

$comments_args = array(
    'label_submit' => 'Submit Comment',
    'title_reply' => 'Post a Comment',
    'comment_notes_after' => ''
);
comment_form($comments_args);

EDIT

What the problem is is that have a page that displays different links to events on it. When I click the link, it opens the record associated with the link, which can be different each time.

So, what I need to have happen, is to have comments associated with the record displayed on that page.

Share Improve this question edited Apr 1, 2021 at 14:24 Darth Mikey D asked Mar 31, 2021 at 18:24 Darth Mikey DDarth Mikey D 931 silver badge9 bronze badges 5
  • What is on line 989 of events.php? That is where you should be looking, not comments.php – Tom J Nowell Commented Mar 31, 2021 at 20:28
  • 989 is just $id = $_GET[‘id’];. This is used to retrieve the database record. – Darth Mikey D Commented Mar 31, 2021 at 23:15
  • Is that file in a plugin? What's the surrounding code? What does the file do? – Tom J Nowell Commented Apr 1, 2021 at 9:16
  • Yes, it is part of a plugin. I am creating an event calendar. What I believe the problem is is that because the page loads different records depending on which link is clicked. This is what the links look like. <a href="<?php echo $newlink . "?id=" . $id; ?>"><?php echo $title; ?></a> $newlink is just the link to the page, $id is the record to retrieve from the database, and $title is the title of the event. So, what needs to happen is the comments need to be associated with the correct record on that page. – Darth Mikey D Commented Apr 1, 2021 at 14:20
  • Is it your plugin? It's difficult to figure out what's going on without seeing more of the code, there's not enough context to figure out how things fit together. Note though that comments are for posts, and by reusing comments for a different table you'll run into weird problems such as comments appearing on unrelated posts that share the same ID. The commenting APIs and files are not built for what you're trying to do. You will need to abandon using comments.php and the official comment form for what you're doing – Tom J Nowell Commented Apr 1, 2021 at 15:13
Add a comment  | 

1 Answer 1

Reset to default 1

This is not possible using the standard comment form. Comments in WordPress are built around post IDs, and are coded with this assumption down to the foundations. Even post statuses that can receive comments are hardcoded at multiple levels.

The comment form itself knows where to go afterwards via the comment_post_ID input.

You will not be able to repurpose the existing comment form to submit comments and have them handled via the normal method. You will need to rebuild the comment form from scratch, as well as the code that submits the comment, and the server-side comment submission handling.

Additionally, comments are intended for posts, and your comments on these custom table records will show up on random posts and attachments, as well as mangling comment counts and sorting

本文标签: pluginsHelp with commentsphp