• 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>
Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter Shashikanta

    (@sashikanta)

    Sure

    I don’t know why the link is not showing, does word press is having any issues ?

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Plz Note : I’m using WP Publications Archive plugins

    According to the forum rules, you should only post 10 lines of code. For more than this, use the pastebin.

    while ( $the_query->have_posts() ) : $the_query->the_post();
       echo '<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>';
    endwhile;

    Your echo line has several errors. Please replace it with these lines:

    ?>
       <h2><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php
Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘How to get lists of files under a category or slug of WordPress’ is closed to new replies.