Support

Account

Home Forums General Issues Displaying posts with custom taxonomy and custom fields

Helping

Displaying posts with custom taxonomy and custom fields

  • Hi all, I am trying to display all posts with certain categories on their corresponding pages. Iv’e set up the categories under WP posts and added a taxonomy field to the new custom post template.

    Here’s what I have so far:

    
    <div class="lt-inner">
    
      <?php
      $post_type = 'post';
      $taxonomy  = 'graphic_assets'; # the post category to query
      $terms = get_field('asset_cat'); # the taxonomy field set up for each new post
    
      foreach ($terms as $term) :
        $args = array(
          'post_type'      => $post_type,
          'posts_per_page' => -1,
          'tax_query'      => array(
            array(
              'taxonomy' => $taxonomy,
              'terms'    => $term,
            ),
          ),
        );
    
        $posts = new WP_Query($args);
    
      ?>
    
        <div class="lt-item">
          <div class="lt-icon">
            <!-- img here -->
          </div>
          <div class="lt-desc">
            <span class="file-name">
              <?php the_field('assets_title'); ?>
            </span>
            <br>
            <?php if (get_field('asset_file')) : ?>
              <span class="file-type">
                <a href="<?php the_field('asset_file'); ?> ">
                  download
                </a>
              </span>
            <?php endif; ?>
            <br>
          </div>
        </div>
    
      <?php endforeach; ?>
      <?php wp_reset_postdata(); ?>
    
    </div>
    

    Everything needs to be inside the ‘lt-inner’ div but i’m not sure where i’m going wrong. And i’m trying to query the post category with slug of ‘graphic_assets’. And then i obviously want that to repeat all the posts with that category and their custom fields.

    I’d like to think i’m close to fixing it, but any help is appreciated. Thanks.

  • I realised I was missing the wp loop for posts duh

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.