WordPress.org

Support

Support » How-To and Troubleshooting » Unattached media archive, sort by category

Unattached media archive, sort by category

  • Hi all,

    I’m trying to set up an archive page that goes and gets all unattached pdfs from the media library and then displays them along with the category each pdf has been assigned via the Media Categories plug-in.

    I have spotted this thread here – http://wordpress.org/support/topic/sort-posts-by-category-2 – and have used that as a basis and tried to combine my existing pdf loop into it. Unfortunately I’m not a php expert and it doesn’t work.

    Can anyone see what I’d have to change to the code below to get it to work please?

    <?php
    global $query_string;
    $my_query_string = $query_string;
    foreach (array('First Category','Odd Pages','Even Posts') as $catname) {
       $catid = get_cat_id($catname);
        $args = array(
                  'post_type' => 'attachment',
                  'post_mime_type' => 'application/pdf',
                  'numberposts' => 6,
                  'post_status' => null,
                  'post_parent' => 0,
    			  'cat' => $catid,
                  'order' => 'desc'
                  );
       $myquery = new WP_Query($args);
       if ($myquery->have_posts()) :
          echo "<h2>Posts for Category $catname</h2>";
          while ($myquery->have_posts()) : $myquery->the_post(); ?>
             <p><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php endwhile;
       endif;
    }
    
    ?>

    Many thanks,

    Adam.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Unattached media archive, sort by category’ is closed to new replies.
Skip to toolbar