Created
November 27, 2019 18:19
-
-
Save JacobLett/c66fd8ec7e095f6dd78631e2d3a45765 to your computer and use it in GitHub Desktop.
get a list of pdf files used for a certain post category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| include "wp-load.php"; | |
| ?> | |
| <?php query_posts('category_name={{yourcategoryname}}&posts_per_page=-1'); ?> | |
| <?php while (have_posts()) : the_post(); ?> | |
| <?php | |
| $args = array( | |
| 'order' => 'ASC', | |
| 'post_type' => 'attachment', | |
| 'post_parent' => $post->ID, | |
| 'date_query' => array( | |
| 'before' => array( | |
| 'year' => 2019, | |
| 'month' => 1, | |
| 'day' => 1, | |
| ), | |
| ), | |
| 'post_mime_type' => 'application/pdf', | |
| //'post_status' => null, | |
| 'numberposts' => -1, | |
| ); | |
| $attachments = get_posts($args); | |
| if ($attachments) { | |
| foreach ($attachments as $attachment) { | |
| echo wp_get_attachment_url($attachment->ID); | |
| echo "<br>"; | |
| } | |
| } | |
| ?> | |
| <?php endwhile;?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment