Support

Account

Home Forums Front-end Issues Outputting count

Helping

Outputting count

  • I’ve got a custom post type for products. This has a number of custom fields.
    My question is how to I output to screen the number of products that are on the page or resulting from a search? Thanks

  • Hi @hs1972,

    You can use WP_Query to get the total post. It should be something like this:

    <?php
    $args = array(
       'posts_per_page' => 5,
       'post_type' => 'product_custom_post_slug',
    );
    $myquery = new WP_Query($args);
    
    echo "<h2>Found: $myquery->found_posts</h2>";
    
    ?>

    To learn more about WP_Query, please take a look at this page: https://codex.wordpress.org/Class_Reference/WP_Query. If you have a further question about this, please ask WordPress forum.

    Hope this helps.

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

The topic ‘Outputting count’ is closed to new replies.