• Resolved eschmidtke

    (@eschmidtke)


    Hi,
    I am trying to display posts (CPT) from a specific category with my custom taxonomy. Im pulling my hair out as there has to be a simple explanation as to why my loop will only display one post despite my post_per_page parameters (8). FYI-my CPT is “Cake Flavors”. My taxonomy is also “Cake Flavors” and within the taxonomy i have about 8 categories: vanilla-flavors, chocolate-flavors, spice-flavors…etc. I want to have a page that shows only vanilla-flavors. Below is my loop code:

    <?php
    
                          $args = array(
                          'post_type' => 'cake-flavors',
                          'posts_per_page' => 8,
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'cake_flavors', // Taxonomy name
                                    'field' => 'slug',
                                    'terms' => array ('vanilla-flavors',)
                                )
                          )
    
                          );
    
                          // The Query
                          $cake_flavors = new WP_Query( $args );
    
                          // The Loop
                          if ( $cake_flavors->have_posts() ) {
    
                            while ( $cake_flavors->have_posts() ) {
                              $cake_flavors->the_post();
    
                            } ?>
    
                             <div class="small-6 columns">
                                    <div class="row">
    
                                      <section>
                                          <div class="small-12 medium-6 columns">
    
                                              <h1><?php the_title() ?></h1>
                                              <p class="description"><?php the_field('description'); ?></p>
                                          </div>
    
                                          <div class="small-7 small-centered medium-6 medium-uncentered columns">
    
                                            <?php // check if the post has a Post Thumbnail assigned to it.
                                            if ( has_post_thumbnail() ) {
                                              the_post_thumbnail('thumbnail');
                                            } ?>
    
                                          </div>
                                      </section>
    
                                    </div>
                              </div>
    
                        <?php
                          } else {
                            // no posts found
                          }
                          /* Restore original Post Data */
                          wp_reset_postdata();
    
                        ?>

    PLeeeeez help! I’m new with WP and a bit overwhelmed so I may be missing something very basic… I tried help from WPMU and I got a canned answer directing me to the codex. I had already read it… Ive read it 1000 times, I still don’t get it… Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter eschmidtke

    (@eschmidtke)

    Perhaps my taxonomies are not set up correctly? I am using Custom Post Type UI Plugin and have created one taxonomy called cake_flavors. I chose the hierarchal option and thought that was what made it a category (as opposed to Tags being non-hierarchal?). I went into the taxonomy and created 8 categories. I need each category to display on a page. Am I missing something? Thanks…

    It looks like you’ve maybe got the naming wrong for your post type or taxonomy as the code looks fine.

    What happens if you remove the taxonomy query and what happens if you remove the post type?

    Thread Starter eschmidtke

    (@eschmidtke)

    If I remove the taxonomy query I get 1 post from my Spice Flavor category???? When I remove the post-type nothing happens

    Thread Starter eschmidtke

    (@eschmidtke)

    If I remove both of those I get 1 post from my chocolate category… ugh….

    Thread Starter eschmidtke

    (@eschmidtke)

    I think I was using the wrong page template… I will try to straighten it out from here. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP_Query not showing correct amount of posts form custom taxonomy’ is closed to new replies.