The MU forums have moved to WordPress.org

Recent comments from all sites SQL (45 posts)

  1. dsader
    Member
    Posted 15 years ago #

    Is comment_post_permalink being added to the sitewide_comments? may need $thispost[0]->guid instead.

  2. leisegang
    Member
    Posted 15 years ago #

    mo there is noe comment_post_permalink added. why not?

    is it because i have the newest version ? 2.6.5

    the db.txt uses capitalied ID on creating the db... you shoud check that out.

    it working now :)

    [What about my exitings comments?]
    how do i get them in there?

  3. dsader
    Member
    Posted 15 years ago #

    "comment_post_permalink added. why not?"

    You need to add a get_permalink of the comment_post_id while it is being saved to the db.

    Existing comments? What's the point? Wait for recent comments.

    http://www.youtube.com/watch?v=7OR0U87mRsY

  4. leisegang
    Member
    Posted 15 years ago #

    now i just get the guid from the post table. how do i add a get_permalink of the comment_post_id while it is being saved to the db?

  5. leisegang
    Member
    Posted 15 years ago #

    anyone?

  6. dsader
    Member
    Posted 15 years ago #

    Contact the plugin author?

    Get a plugin indexer with its own support. http://premium.wpmudev.org/project/comment-indexer

  7. fplus
    Member
    Posted 14 years ago #

    Hello!
    I hope this post will be seen yet?

    Well, I read all what was said...
    First, I can, likeleisegang, output the first blog comments...

    Then, I put the last code done :

    <h2>Recent Comments</h2>
    <?php
    global $wpdb, $blog_id;
    $site_comments = 'sitewide_comments';
    $blog_table = 'wp_blogs';
    
    if ($blog_id > 0 && $blog_id < 3){  // Only for blogs 1 and 2
    $sql = "SELECT * FROM " . $wpdb->base_prefix.$site_comments."
         WHERE comment_approved = '1' AND comment_type = ''
         ORDER BY comment_date_gmt DESC
         LIMIT 20";
      // getting those sitewide comments
      $comments = $wpdb->get_results($sql, ARRAY_A);
      print_r($comments);
    
      // creating a lookup table of blogs
      $all_blogs = $wpdb->get_results("SELECT blog_id, path, domain FROM $blog_table WHERE deleted='0' ORDER BY blog_id");
      $output = $pre_HTML;
      $output .= "\n<ul>\n";
    
      for($i = 0; $i < count($all_blogs); $i++){
        $ach_blog_id = $all_blogs[$i]->blog_id;
        $ach_blog_path = $all_blogs[$i]->path;
    
        if ($ach_blog_path == "/"){
          $ach_blog_path = "MainBlog";
        }else{
          $ach_blog_path = trim($ach_blog_path, "/");
          $ach_blog_path .= "'s page ";
        }
        $ach_blog_lu[$ach_blog_id] = $ach_blog_path;
      }
    
    foreach ($comments as $comment) {
    $blogPostsTable = $wpdb->base_prefix.$comment['blog_id']."_posts";
    $id = $comment['comment_post_ID'];
    $thispost = $wpdb->get_results("SELECT *
    	FROM $blogPostsTable
    	WHERE ID = '$id'
    	AND post_type = 'post'
    	AND post_status = 'publish'
    	");
    
      print_r($thispost);
    // How many characters it will output
    $content_characters = 70;
    // Spacer is the word between author and post title.
    $spacer = ' på ';
    $output .= '<li><a href="' . $comment['comment_post_permalink'] . $thispost ['post_name']. '#comment-'.$comment['comment_ID'].'">'.$comment['comment_author']  .$spacer.  $thispost[0]->post_title . '</a>: <br />'.substr($comment['comment_content'],0,$content_characters);'</li>';
    
    }
    
      $output .= "\n</ul>";
      $output .= $post_HTML;
    
      echo $output;
    }else{
      // Do normal recent comment instead..
    }
    
    ?>

    And I get this error:
    Warning: Invalid argument supplied for foreach() in /home/users4/f/fplus/www/blog2/wp-content/themes/home/home.php on line 165

    Could you help me a little?

    Thank you

  8. SteveAtty
    Member
    Posted 14 years ago #

    So what's in the foreach on line 165 of home.php?

  9. fplus
    Member
    Posted 14 years ago #

    hem
    this:
    foreach ($comments as $comment) {

    Or didn't I understand your question? (sorry I'm French and it's a so long time I didn't speak English).

  10. SteveAtty
    Member
    Posted 14 years ago #

    OK so did the print_r($comments) produce anything?

    You seem to have no check in place for no comments, so if there are no comments returned in the query then I think foreach will complain because its an un-initialised array.

  11. fplus
    Member
    Posted 14 years ago #

    Actually, the print was already in the code, but produces nothing...

    Although I have comments in few differents bogs...

  12. fplus
    Member
    Posted 14 years ago #

    Hello!
    no idea anymore?

  13. fplus
    Member
    Posted 14 years ago #

    hello?

  14. fplus
    Member
    Posted 14 years ago #

    You seem to have no check in place for no comments, so if there are no comments returned in the query then I think foreach will complain because its an un-initialised array.

    but there are somme comments....
    What I don't unsderstand is whe there are not returned ?

  15. fplus
    Member
    Posted 14 years ago #

    Hello!
    Someone to give me a little help?
    Thank you!

About this Topic