How to get lists of files under a category or slug of WordPress
-
I have a category and it has sub-category under these category i have post as attachments.i want to retive only files from this category,for this i use the following code but it was not working?
<ul> <?php global $wpdb; $max_posts = 5; $sql = "SELECT posts.ID, attach.ID attachID, attach.post_title, MIN(attach.post_date) FROM $wpdb->posts posts, $wpdb->posts attach WHERE posts.ID = attach.post_parent AND attach.post_type='attachment' AND attach.post_status = 'inherit' AND posts.post_type = 'post' AND posts.post_status = 'publish' AND posts.post_date <= NOW() GROUP BY posts.ID ORDER BY posts.post_date DESC LIMIT $max_posts"; $postIDs = $wpdb->get_results($sql); foreach ($postIDs as $postID) { the_attachment_link($postID->attachID,false); } ?> </ul>
- The topic ‘How to get lists of files under a category or slug of WordPress’ is closed to new replies.