WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comment template on certain page (5 posts)

  1. baszer
    Member
    Posted 2 years ago #

    Hello,

    I have a page called comments, I also created a custom comment field, now I want to connect these 2. But I can't figure out how.

    This is my code
    <?php comments_template( '/outofthebox-comments.php', true ,$post_id = 250 ); ?>

    250 is the id of the comment page

    what do I do wrong?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    see: http://codex.wordpress.org/Function_Reference/comments_template

    there is no third argument for post ID.

    What do you mean with custom comment field?

  3. baszer
    Member
    Posted 2 years ago #

    in that document:

    Uses global: (array) $comment List of comment objects for the current post
    Uses: $wpdb
    Uses: $id
    Uses: $post
    Uses: $withcomments Will not try to get the comments if the post has none.

    so I thought, I can get the comment form for id but I dont know how.

    I want to have a comment form in a page, but from another page.

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    What you could try is load the page and get the comments and comment form:

    <?php
    $post = get_page($id = 650);
    setup_postdata($post);
    ?>
    <?php comments_template( '', true ); ?>
    <?php wp_reset_postdata(); ?>

    In this example, after you make a comment you will be redirected to the page with $id = 650.

    To remedy this you can put this in your theme's functions.php:

    add_filter('comment_post_redirect', 'redirect_after_comment');
    function redirect_after_comment($location)
    {
    return $_SERVER["HTTP_REFERER"];
    }
  5. baszer
    Member
    Posted 1 year ago #

    Thank you very much,

    this did the trick!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.