We have 300 products and every products contains a user manual. I created a field called pdf_upload where I’ve uploaded a pdf file on each individual product. The file can then be previewed on every single page.
Here is my code:
<?php $pdf_upload = get_field('pdf_upload'); if( $pdf_upload ): ?> <a href="<?php echo $pdf_upload['url']; ?>">Manuel PDF</a> <?php endif; ?>
Now, I want to create a page and display an ordered list of all uploaded PDF by date uploaded. So far, looking at acf documentation I’ve only been able to get the result of a field on a single product page but not all the results uploaded.
How can I display a list of all the PDF’s that has been uploaded?
This is correct. There isn’t any way to get all of the values for all of the posts using any function in ACF or WP. To do what you want to do you would have to query the _postmeta table in the DB directly.
edit: in addition to this, this field in the DB only contains the ID value of the media file (upload) and you would need to get the link to this file yourself. https://developer.wordpress.org/reference/functions/wp_get_attachment_url/
Could you not just add a loop to your page template, loop through all pages/posts and output the ACF field?
<?php $args = array( 'posts_per_page' => -1, 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'fields' => 'ids' ); $wp_query = new WP_Query($args); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); $pdf_upload = get_field('pdf_upload'); if( $pdf_upload ): ?> <a href="<?php echo $pdf_upload['url']; ?>">Manuel PDF</a> <?php endif; endwhile; endif;
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We are currently experiencing an issue with our hosting and our site is down. 😅— Advanced Custom Fields (@wp_acf) September 21, 2021
Apologies for the inconvenience, we'll keep you posted! ^IP
© 2021 Advanced Custom Fields. Subscribe