get_comments example

if ( is_user_logged_in() ) {
                    $comment_args['include_unapproved'] = array( get_current_user_id() );
                } else {
                    $unapproved_email = wp_get_unapproved_comment_author_email();

                    if ( $unapproved_email ) {
                        $comment_args['include_unapproved'] = array( $unapproved_email );
                    }
                }

                $comments = get_comments( $comment_args );

                if ( 'all' !== $parsed_args['type'] ) {
                    $comments_by_type = separate_comments( $comments );
                    if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
                        return;
                    }

                    $_comments = $comments_by_type[ $parsed_args['type'] ];
                } else {
                    $_comments = $comments;
                }
            }
    $comments = array();

    $comments_query = array(
        'number' => $total_items * 5,
        'offset' => 0,
    );

    if ( ! current_user_can( 'edit_posts' ) ) {
        $comments_query['status'] = 'approve';
    }

    while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
        if ( ! is_array( $possible ) ) {
            break;
        }

        foreach ( $possible as $comment ) {
            if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
                continue;
            }

            $comments[] = $comment;

            
return $title;
}

/** * Renders the `core/latest-comments` block on server. * * @param array $attributes The block attributes. * * @return string Returns the post content with latest comments added. */
function render_block_core_latest_comments( $attributes = array() ) {
    $comments = get_comments(
        /** This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php */
        apply_filters(
            'widget_comments_args',
            array(
                'number'      => $attributes['commentsToShow'],
                'status'      => 'approve',
                'post_status' => 'publish',
            ),
            array()
        )
    );

    
'hierarchical' => 'threaded',
            'orderby'      => '',
        );

        $_args           = wp_parse_args( $args$defaults );
        $_args['parent'] = $this->comment_ID;

        if ( is_null( $this->children ) ) {
            if ( $this->populated_children ) {
                $this->children = array();
            } else {
                $this->children = get_comments( $_args );
            }
        }

        if ( 'flat' === $_args['format'] ) {
            $children = array();
            foreach ( $this->children as $child ) {
                $child_args           = $_args;
                $child_args['format'] = 'flat';
                // get_children() resets this value automatically.                 unset( $child_args['parent'] );

                


    if ( post_password_required( $block->context['postId'] ) ) {
        return;
    }

    $comment_query = new WP_Comment_Query(
        build_comment_query_vars_from_block( $block )
    );

    // Get an array of comments for the current post.     $comments = $comment_query->get_comments();
    if ( count( $comments ) === 0 ) {
        return '';
    }

    $comment_order = get_option( 'comment_order' );

    if ( 'desc' === $comment_order ) {
        $comments = array_reverse( $comments );
    }

    $wrapper_attributes = get_block_wrapper_attributes();

    
$args['post_id'] = $post_id;
    }
    $mapping       = array(
        'approved'            => 'approve',
        'awaiting_moderation' => 'hold',
        'spam'                => 'spam',
        'trash'               => 'trash',
        'post-trashed'        => 'post-trashed',
    );
    $comment_count = array();
    foreach ( $mapping as $key => $value ) {
        $comment_count[ $key ] = get_comments( array_merge( $args, array( 'status' => $value ) ) );
    }

    $comment_count['all']            = $comment_count['approved'] + $comment_count['awaiting_moderation'];
    $comment_count['total_comments'] = $comment_count['all'] + $comment_count['spam'];

    return array_map( 'intval', $comment_count );
}

// // Comment meta functions. //
$default_title = __( 'Recent Comments' );
        $title         = ( ! empty( $instance['title'] ) ) ? $instance['title'] : $default_title;

        /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
        $title = apply_filters( 'widget_title', $title$instance$this->id_base );

        $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
        if ( ! $number ) {
            $number = 5;
        }

        $comments = get_comments(
            /** * Filters the arguments for the Recent Comments widget. * * @since 3.4.0 * @since 4.9.0 Added the `$instance` parameter. * * @see WP_Comment_Query::query() for information on accepted arguments. * * @param array $comment_args An array of arguments used to retrieve the recent comments. * @param array $instance Array of settings for the current widget. */
            

function post_comment_meta_box( $post ) {
    wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
    ?> <p class="hide-if-no-js" id="add-new-comment"><button type="button" class="button" onclick="window.commentReply && commentReply.addcomment(<?php echo $post->ID; ?>);"><?php _e( 'Add Comment' ); ?></button></p> <?php
    $total         = get_comments(
        array(
            'post_id' => $post->ID,
            'number'  => 1,
            'count'   => true,
        )
    );
    $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' );
    $wp_list_table->display( true );

    if ( 1 > $total ) {
        echo '<p id="no-comments">' . __( 'No comments yet.' ) . '</p>';
    }
// Check the server connectivity and store the available servers in an option.     public static function get_server_connectivity($cache_timeout = 86400) {
        return self::check_server_connectivity( $cache_timeout );
    }

    /** * Find out whether any comments in the Pending queue have not yet been checked by Akismet. * * @return bool */
    public static function are_any_comments_waiting_to_be_checked() {
        return !! get_comments( array(
            // Exclude comments that are not pending. This would happen if someone manually approved or spammed a comment             // that was waiting to be checked. The akismet_error meta entry will eventually be removed by the cron recheck job.             'status' => 'hold',
            
            // This is the commentmeta that is saved when a comment couldn't be checked.             'meta_key' => 'akismet_error',
            
            // We only need to know whether at least one comment is waiting for a check.             'number' => 1,
        ) );
    }

    

    public function query( $query ) {
        $this->query_vars = wp_parse_args( $query );
        return $this->get_comments();
    }

    /** * Get a list of comments matching the query vars. * * @since 4.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @return int|int[]|WP_Comment[] List of comments or number of found comments if `$count` argument is true. */
    
$offset = 0;
        if ( isset( $struct['offset'] ) ) {
            $offset = absint( $struct['offset'] );
        }

        $number = 10;
        if ( isset( $struct['number'] ) ) {
            $number = absint( $struct['number'] );
        }

        $comments = get_comments(
            array(
                'status'    => $status,
                'post_id'   => $post_id,
                'offset'    => $offset,
                'number'    => $number,
                'post_type' => $post_type,
            )
        );

        $comments_struct = array();
        if ( is_array( $comments ) ) {
            


        /** * Filters the arguments for the comment query in the comments list table. * * @since 5.1.0 * * @param array $args An array of get_comments() arguments. */
        $args = apply_filters( 'comments_list_table_query_args', $args );

        $_comments = get_comments( $args );

        if ( is_array( $_comments ) ) {
            $this->items       = array_slice( $_comments, 0, $comments_per_page );
            $this->extra_items = array_slice( $_comments$comments_per_page );

            $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );

            $this->pending_count = get_pending_comments_num( $_comment_post_ids );
        }

        $total_comments = get_comments(
            
Home | Imprint | This part of the site doesn't use cookies.