Support » Plugin: Comments - wpDiscuz » WPdiscuz does not work inside WP Query

  • Resolved perminna

    (@perminna)


    I have a use case where I want to include a page/post with comments onto same page as another page/post. I have closed the comments for the main page/post but have comments open for the additional page/post. The comments and comment form load as required (using WP_Query() and comments_template()) but WPdiscuz does not take over here.

    If I turn on comments for the main page/post, both comment sections (main and secondary) do have WPdiscuz in use. I want to have the possibility to have comments closed for the main loop but open for the second query.

    //$discussion_id is the page id of the page I want to include
    $args = array(
    'page_id' => $discussion_id,
    );
    
    $discussion = new WP_Query( $args );
    
    if ( $discussion->have_posts() ) :
    while ( $discussion->have_posts() ) :
    $discussion->the_post();
    
    //displays the content
    get_template_part( 'partials/content', 'discussion' );
    
    // this same code works w/o problem with the main loop
    if ( comments_open() || get_comments_number() ) :
    comments_template();
    endif;
    
    endwhile;
    endif;
    
    wp_reset_postdata();
    • This topic was modified 1 month, 1 week ago by perminna.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.