• Ok, I ‘ve a taxonomy archive page, with multiple loops and I’m trying to show all attachments with this term.

    But I’m getting this error code AFTER the attachments:
    Fatal error: Call to a member function have_posts() on a non-object in… I’m not very good with PHP. Any help, pleaseee?

    <?php $queried_object = get_queried_object();
        $term_id = $queried_object->term_id; 
    
    	$args = array(
    	'post_status' => 'inherit',
    	'numberposts' => 0,
    	'post__not_in' => array_merge($do_not_duplicate,get_option( 'sticky_posts' )),
    	'post_type' => 'attachment',
    	);
    
    	$args['tax_query'] = array(
    	array(
    		'taxonomy' => 't-arte',
    		'terms' => $term_id,
    		'field' => 'id',
    		),
    		);
    
    	$media_query = new WP_Query( $args)?>
    
        <?php  if($media_query->have_posts()) : while ($media_query->have_posts() ) : $media_query->the_post();
    	if( $post->ID == $do_not_duplicate ) continue; ?>
    
        <?php $t = $data['t-arte'];
    	$array = explode(" ", $t);
    	$array = array_unique($array);?>
    
    	<?php $media_query = array_unique($array); ?>
    
    	<div id="archivespage-media-item">   
    
                <?php $attachments = get_posts( $args );
                 if ( $attachments ) {
                 foreach ( $attachments as $attachment ) {
                 echo '<div id="imagem">';
                 the_attachment_link( $attachment->ID, true );
                 echo '</div>';
                 $do_not_duplicate[] = $post->ID; }
                 }?>
    
        </div>
    
        <?php endwhile; else: ?>	
    
         //do stuff       
    
         </div>
    
         <?php endif; ?>
  • The topic ‘Call to a member function have_posts() on = Taxonomy archive attachments’ is closed to new replies.