-
-
Notifications
You must be signed in to change notification settings - Fork 513
term.get_posts not returning all posts in a loop #1366
Copy link
Copy link
Closed
Description
when I get available terms for a CPT, and then try get the posts for those terms in a loop, some of my terms are showing 0 posts.
am I doing something wrong? I'm essentially doing the same as this
#507 (comment)
thanks
code excerpts:
page.php
--------
//...
$doc_categories = Timber::get_terms('document_category');
$context["doc_categories"] = $doc_categories;
//...
page.twig
---------
{% for doc_category in doc_categories %}
<h1>{{doc_category}}</h1>
{% set category_docs = doc_category.get_posts() %} {# wrongly getting 0 posts for some cats#}
{% for doc in category_docs %}
{{doc.title}}<br />
{% endfor %}
{% endfor %}working vanilla WP code
$doc_categories = get_terms( array(
'taxonomy' => 'document_category',
'hide_empty' => false,
) );
foreach($doc_categories as $doc_category) {
echo($doc_category->slug."<BR>");
$args = array(
'post_type' => 'document',
'tax_query' => array(
array(
'taxonomy' => 'document_category',
'field' => 'slug',
'terms' => array( $doc_category->slug )
)
)
);
$docs = get_posts($args);
print_r($docs); // the output shows docs that are missing in the timber loop
}Expected behavior
All posts for a specific taxonomy term should be listed
Actual behavior
Some terms are showing 0 posts, even though the raw term data shows a count > 0
Steps to reproduce behavior
(see below)
What version of WordPress, PHP and Timber are you using?
WordPress 4.7.2, PHP 5.6.29, Timber 1.24
How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)
Installed from WP "Add Plugin"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels