How to perform specific count of custom posts in wordpress

0

Hello, I would like your help with the following problem, I would like to know how I can count WordPress posts, using the settings imposed in the code below, to count only posts with meta_key , tipo_de_item value Novo , with post parameter publish .

<?php
/*
Template Name: DT - Revistas
*/
get_header();
doo_glossary('listagem');
global $user_ID;
$dt = isset( $_GET['get'] ) ? $_GET['get'] : null;
$admin = isset( $_GET['admin'] ) ? $_GET['admin'] : null;
echo '<div class="module"><div class="content">';
get_template_part('inc/parts/modules/featured-post-tvshows');
echo '<header><h1>'. __d('Novas'). '</h1></header>';
echo '<div id="archive-content" class="animation-2 items">';
// Ordenar em ordem alfabetica
global $wp_query;
$pages = $wp_query->max_num_pages;
query_posts(array(
    'posts_per_page' => $pages,
    'paged' => $paged,
    'post_type'     => array('revista'),
    'meta_key'      => 'tipo_de_item',
    'meta_value'    => 'Novo',
    'order'         => 'ASC',
    'orderby'       => 'title'
));
if (have_posts()) {
    while (have_posts()) {
        the_post();
        get_template_part('inc/parts/item');
    }
}
echo '</div>';
if ( function_exists("pagination") ) {
    pagination();
}
echo '</div>';
get_template_part('inc/parts/sidebar');
echo '</div>';
get_footer();
    
asked by anonymous 17.08.2018 / 10:23

1 answer

1

You said "count", for example "10 posts" Answer: Add this snippet to the following line of code: Here's how:

if (have_posts()) {
    while (have_posts()) {
        the_post();
        get_template_part('inc/parts/item');
    }
}

It will look like this:

if (have_posts()) {
echo $wp_query->found_posts.' Posts'; // Exibe 'x' Posts
    while (have_posts()) {
        the_post();
        get_template_part('inc/parts/item');
    }
}
    
17.08.2018 / 16:23