Search code examples
wordpresstemplatescommentsblogscustom-wordpress-pages

Post comments using post ids Wordpress


I’m trying to use blogs(posts) with two different designs First, for non-loggedin(guest) users which access blogs from website (Example URL – Click Here) Second is for logged in users which access blogs from their frontend dashboard

For the first case, I am using single.php and For the second case, I’m using custom template in user’s dashboard and fetching posts using post ids.

QUERY ——————–

So the question is how to post comments to post using post id i.e for the second case? E.g post url is: http://yourdomain.com/blogs/?pid=23

Here is attached video which highlights the query Unable to display content. Adobe Flash is required.

Further, is there any other way to achieve the above scenario i.e. two different designs

Let me know in case of more clarification.


Solution

  • You can use a normal loop in your custom query for logged in users

    for example

    <?php
    $args = array(
    
        'post__in' => array(1,2,4,6),
        'post_type'  => 'post',
    
    );
    // the query
    $the_query = new WP_Query( $args ); ?>
    
        <!-- the loop -->
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
          // put your code here
        <?php endwhile; ?>
    
        <!-- end of the loop -->
        <?php wp_reset_postdata(); ?>
    

    this way you should not be worry about getting comments by post id (the loop will handle the id for you)