Hello!
Need help with my code. I have several PDFs and PPTs all named by their date in the filename. YYYY-M-D.pdf with no leading zeros. I would like today's date of M-D to match the filename's M-D and use substr() to remove the first five characters of the filename to check for the match. Then it needs to list only those that match the today's date and provide a link that opens in a new window. Each link is separated by a space and showing the full filename without the extension, using glob() to find a match if necessary.
<?php
date_default_timezone_set('America/New_York');
$todayNoYear = date('n-j'); // Month - Day
$args = array( 'post_mime_type' => 'application/pdf', 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'post_parent' => null );
$attachments = get_posts( $args );
$attachmentTitle = apply_filters( 'the_title' , $attachment->post_title );
$titleNoYear = substr($attachmentTitle, 5);
if ($attachments) {
if ($todayNoYear == $titleNoYear) {
echo 'PDF for Today: ';
foreach ( $attachments as $attachment ) {
$attlink = the_attachment_link($attachment->ID, false);
echo $attlink.' ';
}
} else {echo 'none';}
}
?>