Skip to content

Instantly share code, notes, and snippets.

@JacobLett
Created November 27, 2019 18:19
Show Gist options
  • Select an option

  • Save JacobLett/c66fd8ec7e095f6dd78631e2d3a45765 to your computer and use it in GitHub Desktop.

Select an option

Save JacobLett/c66fd8ec7e095f6dd78631e2d3a45765 to your computer and use it in GitHub Desktop.
get a list of pdf files used for a certain post category
<?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