Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:34:45+00:00 2026-05-17T22:34:45+00:00

I want to have a page that shows all posts, separated by category. The

  • 0

I want to have a page that shows all posts, separated by category. The idea is to get the categories, and then iterate through all posts for each category. The problem is complicated by the fact that I want to iterate through all posts of a given custom type, using a custom taxonomy as the categories. (Running WordPress 3)

In my functions.php, my custom post type is registered as “video” and the custom taxonomy as “video_types”.

In my custom page template that is supposed to show all videos arranged by category, this is the code that isn’t returning any posts (and they’re there, I checked):

<?php 
  $categories = get_categories(array(
    'taxonomy' => 'video_types'
  )); 
  foreach ($categories as $cat):
?>
 <section id="<?php $cat->slug ?>" class="video-category">
     <?php
  query_posts(array(
      'cat' => $cat->cat_ID,
      'posts_per_page' => -1
         ));
     ?>
     <h2><?php single_cat_title(); ?></h2>
    <p class="description"><?php echo category_description($cat->cat_ID); ?></p>
  <?php while (have_posts()) : the_post(); ?>
      <?php
       $category = get_the_category(); 
            echo $category[0]->cat_name;
      ?>
      <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
      <article class="video">
        <h3><?php the_title(); ?></h3>
        <p>
          <?php the_content() ?>
        </p>
      </article>
  <?php endwhile; ?>
 </section>
<?php endforeach; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:34:46+00:00Added an answer on May 17, 2026 at 10:34 pm

    Jeez, once you figure out that each item of a custom taxonomy is called a term (not immediately obvious in the wordpress docs for the noob), its all much simpler to search for. This solution is easier to understand without all the custom query stuff.

    <?php
    // A term is an item of a taxonomy (e.g. "Promotional" could be a term for the taxonomy "video_type")
    // ...so $categories could be $terms and it would still make sense
    $categories = get_terms('taxonomy_name');
    foreach( $categories as $category ):
    ?>
      <section class="category-<?php echo $category ?>">
        <h2><?php echo $category->name; // Print the cat title ?></h2>
        <p class="description"><?php echo $category->description ?></p>
        <div class="<?php echo $category->post_type ?>-list">
          <?php
          //select posts in this category (term), and of a specified content type (post type) 
          $posts = get_posts(array(
            'post_type' => 'custom_post_type_name',
            'taxonomy' => $category->taxonomy,
            'term' => $category->slug,
            'nopaging' => true, // to show all posts in this category, could also use 'numberposts' => -1 instead
          ));
          foreach($posts as $post): // begin cycle through posts of this category
            setup_postdata($post); //set up post data for use in the loop (enables the_title(), etc without specifying a post ID)
          ?>
            // Now you can do things with the post and display it, like so
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
              <h3><?php the_title(); ?></h3>
              <?php 
                // Getting custom field data example
                echo get_post_meta($post->ID, 'field_key', true); 
              ?>
              <?php the_content() ?>
            </article>
          <?php endforeach; ?>
        </div>
      </section>
    <?php endforeach; ?>
    

    And then any gaps in understanding can be filled by searching the functions above in the wordpress codex. In the above code, for my specific application, custom_post_type_name would be video, and taxonomy_name would be video_type (or video_types, I forget).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that displays posts and I want to get the name
Context: I have an app that shows posts and comments on the home page.
I have a page that above it I want to have a panel that
I am working with php and want to have a page that has a
I'm new to using SugarCRM. I want to have a users page that does
I have a page that I want to update non stop, every few seconds.
I have a page that I want to be styled differently depending on whether
I have a page that displays messages and I want it to work just
i have a page that contains several submit buttons however i only want one
I have a page that requires jQuery.tmpl, but I want to use native knockout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.