I'm creating a site where I want to use the comment box to auto-generate a FAQ page.

In essence, when a comment is posted it won't appear on the same page as the comment box. Instead, it will be displayed on a secondary "Faq" page. On the page editor, I'd like to simple add a custom field where I input the post ID of the other page, pass and use that to generate a page that is composed entirely of the comments from the parent page.

Here's what the relevant portion of my code looks like at the moment:

$faqpagenum = get_post_meta($post->post_parent, 'faqpagenum', true);
if (isset($faqpagenum) {
        $faqs = get_comments(array('post_id'=>$faqpagenum));

Unfortunately, every time I try this, I keep getting "Parse error: syntax error, unexpected '{' in..."

With the reference line being the line beginning with $faqpagenum.

So, what am I doing wrong? I'm at the point where I feel like I'm missing something obvious.

EDIT: I'm also considering using wp_get_post_parent_id to automatically pull the parent ID and pull the comments without the need for a custom field, so if you have an idea along those lines, I'm all ears.

  • 1
    You've a syntax error in if (isset($faqpagenum) {. Try for example if ( ! empty( $faqpagenum ) ) { instead. – birgire May 28 '15 at 2:17
  • Awesome thanks! That works! I knew I had to be missing something obvious. – Nick Fox May 28 '15 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.