Okay, what I am trying to do here is simple.
I’ve created a Post Object field on the backend. The field allows you to select an attachment from the drop down menu that is basically a bunch of PDFs I’ve uploaded to the site.
My code for outputting the direct link to this PDF in my template is as follows:
$post_object = get_field('product_brochure');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
However, that code outputs the link to the attachment itself (i.e. http://test.pr-tech.com/?attachment_id=175), NOT the direct link to the PDF which is what I was hoping for.
What am I missing here?
Also, the page in question is here: http://test.pr-tech.com/product/spanguard-abs-standard-power-line-marker/
You can see in the intro section where it says ‘SpanGuard Brochure (PDF)’ which is where I using this PHP code above. It is indeed outputting the correct title of the attachment, but it’s linking to the attachment page instead of the PDF itself.
the_permalink() you want to use