WordPress.org

Ready to get started?Download WordPress

Forums

Comments on Post with featured image get attached to image and not post. (10 posts)

  1. Chris-Kay
    Member
    Posted 2 years ago #

    I have purchased a custom theme and was able to install it without major problems. I now have a very specific issue.

    When I create a post the comment system works fine. However when I add a featured image to the post the comments get added to Image and not the post that the image is attached to.

    I have narrowed it down (I think) to the fact that when trying to post a comment it assigns the comment_post_ID in WP's wp-comments-post.php to the featured image and not the post the image is attached to. As soon as I remove the featured image from the post the comment get posted as normal (this is always possible when you reply to a comment on a post regardless if the post has a featured image or not).

    I have no idea if this is a Theme issue, a general WordPress issue or something that accidentally got changed while I was customizing the theme. Support from the site I bought the theme from is rather slow so I thought I'd try here.

    Seeing as I am relatively new to WordPress your assistance in this issue would be greatly appreciated!

  2. Jackson
    Member
    Posted 2 years ago #

    Sounds like an issue with your theme.* I would look at the code that is displaying the image, if it's doing something strange like modifying the main query on the page and then not resetting it.

    You'd really need to show the code (wordpress.pastebin.com)

    * You can check very easily if this is related to your theme. Switch to the default theme and see if the behavior persists. If it does - it's not your theme, if it goes away.... well you get the idea.

  3. Chris-Kay
    Member
    Posted 2 years ago #

    Thanks for your reply.

    I tried switching to another theme and the problem wasn't there.

    I located the problem.

    <p class="form-submit">
    <input name="submit" type="submit" id="submit" value="Plaats Reactie" />
    <input type='hidden' name='comment_post_ID' value='420' id='comment_post_ID' />
    <input type='hidden' name='comment_parent' id='comment_parent' value='0' />
    </p>

    This piece of code attached to the comment submit button is getting the wrong value. In this case the 420 is the featured image and not the post. With Chrome browser developer mode I manually changed the value to match the post and the comment was correctly attached.

    So..... where do I locate this code and how do I change it?

  4. Jackson
    Member
    Posted 2 years ago #

    How about a link to the site?

  5. Chris-Kay
    Member
    Posted 2 years ago #

    http://www.bekendeburen.nl

    The code I posted above is from the post http://www.bekendeburen.nl/?p=441 which has http://www.bekendeburen.nl/?attachment_id=420 as a featured image.

  6. Jackson
    Member
    Posted 2 years ago #

    OK, that is screwy.

    What's strange is the comments links right above the form have the correct ID.

    Just to be sure, is your theme using comment_form();

    To output the comment form? You'd likely find this in comments.php, single.php or index.php - but entirely dependent on the theme.

    If this is a paid theme, your quickest answer maybe from the theme developer.

  7. Chris-Kay
    Member
    Posted 2 years ago #

    Yes it's screwy and I don't know why.

    Yes if you click reply(beantwoorden) on 1 of the comments then it does have the correct ID. Something is making the attachment(featured image) give the default value with regular posting of comments.

    1 of the last lines of code in the themes comments.php is
    comment_form( $defaults ); ?>
    so I assume this is the case.

    Like I stated in the original post. Support from the theme developer is a bit slow so I thought I would try here to speed up the process.

    Anyways thanks for having a look.

  8. Chris-Kay
    Member
    Posted 2 years ago #

    Well I figured out a temporary fix.

    Somehow the variable $id was not corresponding with the $post_id when the function get_the_ID(); from post-template.php was called to assign a comment to a post. $id was being assigned to the attachment and not the post the attachment was on.

    I have now changed wp-includes>comment-template.php in the function comment_form(); (line: 1510)

    >>>>from

    if ( null === $post_id )
    $post_id = $id;
    else
    $id = $post_id;

    >>>>into

    if ( null === $post_id )
    $post_id = $post_id;
    else
    $id = $post_id;

    It works now but I still don't know why the id is being overridden by the featured image. If anybody every figures out why please let me know.

  9. Jackson
    Member
    Posted 2 years ago #

    Yikes. If you have to modify core to get a template to work right you should ask for a refund or a fix. Perhaps your theme is using query_posts wrong somewhere before the comment form which is messing things up. It's nearly impossible to tell without seeing the PHP code in your theme.

  10. ashes999
    Member
    Posted 2 years ago #

    I had the same problem. For anyone reading this later, here's the breakdown.

    The root cause is mangling of the main loop, visible by wp_reset_query or something like that called in your function.

    Look for your comment form code. If it looks like:

    comment_form($defaults)

    You need to change it to

    comment_form($defaults, get_the_id())

    ... and everything should work :)

Topic Closed

This topic has been closed to new replies.

About this Topic