WordPress get_post_count?

1 Cevap php

Ben belirli bir sorgu için mesajlarınızın sayısını alır bir işlev oluşturmak istiyorum. Ben bu amaç için pahalı yolunda Açıkçası get_posts kullanmak istemiyorum. Ancak, bu bir get_post_count işlevi oid'in kullanmak için yaşıyorum tam olarak buydu.

Benim kod ...

global $post;
$cat=get_cat_ID('mymenu');
$catHidden=get_cat_ID('hidden');
$myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'showposts' => $NumberOfPostsToShow));
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'showposts' => -1));
$myrecentpostscount = count($myrecentposts2);

Not: get_posts () bir çekirdek WP fonksiyonudur.

1 Cevap

Yeni bir WP_Query nesnesi oluşturabilir, ve found_posts özellik mesaj sayınız olacaktır.

$myquery = new WP_Query();
$myquery->query(array(
    'cat' => "-$cat,-$catHidden",
    'post_not_in' => get_option('sticky_posts'),
    'posts_per_page' => $NumberOfPostsToShow
));

$myrecentpostscount = $myquery->found_posts;