Home Forums General Issues Display counter inside the post loop


Display counter inside the post loop

  • I’d like to make a small review section on my website.

    So I created a custom text field called ‘review-company’.

    I’d like to show how many reviews the company left by displaying a small tag.

    I found this part of code

    global $post;
    $my_meta = get_post_meta( $id, 'review-company', true);
    $reviews = get_posts( array(
    'post_type' => 'review',
    'posts_per_page' => -1,
    'meta_query' => array(
      'key' => 'review-company',
      'value' => $my_meta,
      'compare' => '=' )
    ) );

    I assume I should now echo the counter inside my actual post loop below the first part:

    ‘ global $post;
    $postslist = get_posts( array( ‘post_type’ => ‘reviews’, ‘posts_per_page’ => 20, ‘order’=> ‘ASC’, ‘orderby’ => ‘date’ ) );
    foreach ( $postslist as $post ){

    // Tag counter

    echo $reviews-number

    // Tag counter end


  • You should be able to get the post count after you run your query:

    For example:

    echo "<span>".$postslist->post_count."</span>";

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Display counter inside the post loop’ is closed to new replies.