It is necessary to deduce from the database: title, link, number of views and number of comments. Now I can not bring the number of comments in the record and they are in a different table. Save !!)). Records are not standard WordPrese, but from the Asgaros Forum plugin.

$posts = $wpdb->get_results("SELECT * FROM wp_forum_topics ORDER BY id DESC LIMIT 3"); $posts_comment = $wpdb->get_results("SELECT * FROM wp_forum_posts WHERE parent_id=1 LIMIT 3"); ?> <ul> <?php foreach ($posts as $posts_i) { ?> <li> <a href="/sample-page/?view=thread&id=<?php echo $posts_i->id ?>"><?php echo $posts_i->name ?></a> <span>Просмотры: <?php echo $posts_i->views ?></span> <span>Коментарии: <?php foreach ($posts_comment as $posts_comment_i) { ?> <?php echo $posts_comment_i->parent_id ?> <?php } ?> </span> </li> <?php } ?> 

Raised to the main page by a community spirit member 20 hours ago .

This question contains answers that can be both good and bad; the system offered them for verification.

    2 answers 2

    Since the question is corrected after discussion in the comments, the answer is: I don’t know anything about the Asgaros Forum plugin. Below is the answer for standard comments on WordPress posts.

    WordPress has features for every occasion.

     $num = get_comments_number( $post_id ); 

    And to get comments in the form of an array

     $comments = get_comments( $args ); foreach( $comments as $comment ){ // вывод } 
    • The fact is that the posts are on the Asgaros Forum plugin. Standard output will bring them? - user258149
    • And why do you have a word about this? I do not know, you need to watch how the plugin works - KAGG Design
    • In the description added information, corrected) - user258149

    wp_count_comment ($ post_id); returns the object with the number of comments.

    For example:

     $comments_count = wp_count_comments( $post_id ); echo $comments_count->approved; // выведет количество одобренных комментариев 
    • It will output the number of comments from the plugin, and not from WordPress? I need to pull out of the database, as I understand it, just how to do it right? I have 3 tables in wp_forum_topics wp_forum_posts wp_forum_forums. How do I pull data from wp_forum_posts so that it displays normally? - user258149
    • it seems that comments are provided in the form of records of a certain type. if so, then you can try wp_count_posts( $post_type ) if the method is working, let me fix my answer :) - Sergey Khomenko
    • Please tell me where it is to insert in my code? But I do not quite understand - user258149
    • Made a screen base, can it help ? ) joxi.net/KAgBexaCgYKbj2 can somehow add posts from the same parent_id and transfer a specific record? - user258149