Category objects returned by API have count of posts on them in count
field. You should simply check that and skip rest of the iteration for those that have no posts.
Something like:
foreach( $categories as $category ) {
if( 0 == $category->count ) {
continue;
}
Scratch that. If I get it right this time what you really need is to check if you got any posts before you output category header. Something like (don’t use query_posts()
by the way, it’s trouble):
$stuff = new WP_Query( $args );
if ( $stuff->have_posts() ) {
?><a href="#" class="list-group-item active"><?php echo $category->name; ?></a><?php
while ( $stuff->have_posts() ) : $stuff->the_post();
// posts output
endwhile;
}
Related Posts:
- Altering the appearance of custom taxonomy inputs
- How to get WooCommerce Product Category Link by ID?
- Adding An Image To A Custom Taxonomy Term
- How to display a listing template of a certain taxonomy?
- How do I filter posts by taxomony using AJAX
- Post Formats in the context of the Database ‘Save Post’ function
- Rewrite rule for custom taxonomy
- Dropdown: Display terms from B only if has relationship with a term A selected
- Showing posts by collection of specific terms and texonomy
- How do I rewrite a url to use %taxonomy% instead of %category% when multiple taxonomies are present?
- Custom taxonomy – custom sortable column
- How do you add custom taxonomy capabilities exactly?
- WP redirects pretty permalink to query string
- Custom WP_Query breaks default behaviour of viewing right post associated with tax-term!
- How to modify default taxonomy field to a single text field?
- How to set hierarchical terms to a post using wp_set_object_terms
- Adding Custom taxonomies to Press This panel
- Check if post has a specific post type
- List taxonomy / category count showing list published posts only
- Taxonomy page lead to 404 page on pagination
- Excluding a custom taxonomy term breaks wp_get_post_terms
- Can I turn off write-in tags/taxonomies?
- How to get Custom Taxonomy ID from the post ID
- Modify main loop in taxonomy archive page
- Displaying a custom taxonomy term’s name & description
- Storing an array using update_metadata [closed]
- Display Terms for all posts in Current Archive or Query
- How do I sort posts by custom taxonomy?
- Solve product properties with custom taxonomies?
- Some Custom Taxonomy modified dates return false
- Is echo get_the_term_list and get_field in a template file considered safe?
- Remove alphabetical order from wordpress categories
- Is it possible to get all term items from a custom taxonomy regardless of post attachment status?
- Permalinks for custom taxonomy stopped to work
- Filter WooCommerce admin products list by a custom taxonomy
- Get custom category image from menu
- get_category_link returning page URL
- Adding content to a taxonomy metabox
- Getting values of a custom taxonomy dropdown
- What is faster: custom taxonomy or serialized post-meta for db retrieval? (over 60,000 posts)
- Get taxonomy based on another taxonomy slug
- How does WordPress Parent-Child Taxonomy actually Works?
- Custom taxonomy archive shows 404 error
- Getting associated taxonomies
- Can’t set custom taxonomy terms via custom form
- Custom taxonomy not appearing in menu administration panel
- how can i display taxonomy instead of category on my web page?
- Taxonomy Meta Box in User Profile?
- If Custom Taxonomy
- What does ‘category__in’ mean in queries?
- Use the same taxonomy twice on the same post type?
- When filtering query on custom taxonomy; main menu dissapears
- Get all terms, including unchecked, or get the terms outside loop
- get_term_link not working
- My custom taxonomy page is leading in 404 page
- Show template part if part of term
- Different Taxonomy Values for Each Post
- List Top 5 taxonomy terms based on number of post
- Get list of taxonomies associated with users
- check if a taxnomy queried in $wp_query?
- Taxonomy.php how to show post only in current taxonomy with wp_query?
- Include get_term_link inside search
- Shortcode to show the terms from the current post (custom post type & custom taxonomy)
- Change the full permalink (URL) of a single post by connecting it to a specific page
- Items from media library won’t get added to a custom taxonomy
- Custom field with terms from another taxonomy programmatically
- Taxonomies and subtaxonomies relations
- How to change Custom Permalink for Taxonomy? (remove the slashes from term-slug)
- Add A CSS Class To A Menu Item When A Custom Taxonomy Term is Present On Single Post
- Retrieve & Display User Meta Values from Checkboxes
- Custom taxonomy if statement
- Hierarchical taxonomies in permalink cause 404 for sub term archive
- How do I check to see if a specific child term has shared posts with another set of child terms within the same taxonomy?
- Output slugs to use as class names for every taxonomy a post is attached to
- Group & Sort Taxonomy terms by letter – Is there a better way?
- Custom Taxonomy Archive Page for Parents AND Children?
- Custom taxonomy page template name and how to use it?
- Conditional Logic Based on Custom Taxonomy
- How to get name of custom taxonomy
- How to save custom taxonomy archive as a page template?
- Multiple taxonomies, what should the permalink look like?
- Child Pages and Custom Taxonomies
- Display the first tag assigned to a post
- Determine if Term has Grandparent/Great-Grandparent
- Sorting Custom Taxonomy in ASC/DESC order?
- Saving Taxonomies to Post Revisions
- Order posts by month – in custom taxonomy template
- Are taxonomy hierarchies possible?
- Filer taxonomy posts by current category
- Loop custom post type by taxonomy (Category)
- Error when adding custom taxonomy to wp nav menu
- Create heirachy of post terms from array & assign post to terms
- How much worse is querying custom fields compared to custom taxonomies, quantitatively
- Nested Accordions For Taxonomies [closed]
- Complex Taxonomy scheme
- Display posts from specific slug of the custom taxonomy in WordPress
- Add custom display condition to Elementor Theme Builder for custom taxonomy children, grandchildren, and great-grandchildren
- Taxonomy term template is not working
- Registering custom taxonomy using reserved terms
- Show taxonomy term meta field on single template