0

Trying to list two columns of attachments (pdfs), each with taxonomies (tags) of either "sub" or "ins". I almost have it but no quite:

<?php 
    $terms_array = array( 
      'taxonomy' => 'post_tag', 
        );
    $services_terms = get_terms($terms_array); 
    foreach($services_terms as $service): ?>
    <h4><?php echo $service->name; ?></h4>
    <?php 
    $post_args = array(
            'post_type' => 'attachment',
            'post_mime_type' => ['application/pdf'],
            'numberposts' => -1,
            'post_status' => null,
            'post_parent' => null, 
            'tax_query' => array(
                    array(
                        'taxonomy' => 'post_tag',
                        'field' => 'slug',
                        'terms' => 'sub', // ['sub', 'ins'] does not work
                    )
                )
            );      
    $myposts = get_posts($post_args); ?>
    <ul>
    <?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
      <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
      </li>
    <?php endforeach; // Term Post foreach ?>
    </ul>
    <?php wp_reset_postdata(); ?>

    <?php endforeach; // End Term foreach; ?>  

Right now this is passing only the "sub" tags, obviously. Any help?

  • terms value should be an array array('sub','ins') did you try use array? – Serkan Algur Dec 10 '18 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.