WordPress.org

Ready to get started?Download WordPress

Forums

How to search for attachments (1 post)

  1. dtrickky
    Member
    Posted 2 years ago #

    Hi all,
    I'm working in my search.php file in an attempt to 1) display attachments 2) separate the posts from attachments when the results are shown.

    The code I'm working with is as follows, but it doesn't seem to be picking up any attachments I have on my site.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php  if ($post->post_status == 'attachment' && $post->post_status == 'inherit') {  ?>
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	     <a href="<?php echo wp_get_attachment_url(); ?>"><img src="/wp-content/themes/uccx/img/btn/download_icon.png" alt="Download" /></a> -- <?php the_attachment_link( $attachment->ID, false ); ?> -- <?php the_time('M j, Y'); ?> -- <?php the_content(); ?>
    	</article><!-- #post-<?php the_ID(); ?> -->
    
    <?php  } elseif ($post->post_type == 'post')  {?>
    <div id="title_post"><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><small><?php edit_post_link('Edit this entry ยป', '', '  '); ?> </small>
    <?php the_excerpt(); ?>
    </div>
    <?php } ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Any suggestions as to what I am missing would be greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic