How to perform specific count of custom posts in wordpress

Asked

Viewed 42 times

0

Ola would like the help of you for the following problem, I would like to know how I can perform the count of Wordpress posts, using the settings imposed in the code below, to perform the count only posts with meta_key , tipo_de_item value Novo, with posting 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();

1 answer

1


You said "count", for example "10 posts" Answer: Add this snippet to the following line of code: It’s like this:

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

Will Stay So:

if (have_posts()) {
echo $wp_query->found_posts.' Posts'; // Exibe 'x' Posts
    while (have_posts()) {
        the_post();
        get_template_part('inc/parts/item');
    }
}
  • Thank you Reply however, I forgot to mention that the count should be able to calculate all existing items, in which case the function you passed only counts the number of items per page. I need in case you count all existing items with these parameters contained in the database.

  • You could try switching from post_count to found_posts ?

  • Can you sort my answer? xD just click the arrow up s2 I’d appreciate it if you could. haha xD And you’re using dooplay or some Doo theme, right? xD

  • Yes, you would tell me how can I activate the Letter mode ? I asked a question about this no longer obitive answer yet.

  • Is that your questions are not very clear face kkkkkk But I know inform yes, I will answer there on topic

  • I’m sorry, and I don’t know the technical terms.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.