• How would you recommend outputting the PDF thumbnail in this situation? I’ve tried your code example but they haven’t worked for me.

    <?php
    
                      // check if the repeater field has rows of data
                      if( have_rows('resource_upload') ):
                      ?>
                        <ul class="resource-feed">
                          <?php
                            // loop through the rows of data
                              while ( have_rows('resource_upload') ) : the_row();
                              // display a sub field value
                              $docTitle = get_sub_field('document_title');
                              $docLink = get_sub_field('document_upload');
                          ?><li>
                              <a href="<?php echo $docLink; ?>" target="_blank"><div class="thumbnail"></div></a>
                              <div class="doc-content">
                                <h2><?php echo $docTitle; ?></h2>
                                <h3><a href="<?php echo $docLink; ?>" target="_blank">Download</a></h3>
                              </div>
                            </li><?php
                              endwhile;
                           ?>
                        </ul>
                      <?php
                        else :  // no rows found
                      endif;
                      ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter mondererdesign

    (@mondererdesign)

    I figured it out. I was able to use this code to get the PDF ID from the attachment URL, and then use the ID to display the thumbnail.

    https://pippinsplugins.com/retrieve-attachment-id-from-image-url/

    Hey mondererdesign, i’m curious about how you made it, could you maybe post your result code here, i’m searching for the same problem ?? Thanks

    Thread Starter mondererdesign

    (@mondererdesign)

    Hi @nroillet,

    Here’s how I did it…

    Added to functions.php:

    // retrieves the attachment ID from the file URL
    function pippin_get_image_id($image_url) {
    	global $wpdb;
    	$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); 
            return $attachment[0]; 
    }

    Added to my template file:

    <ul class="resource-feed">
              <?php
                // loop through the rows of data
                  while ( have_rows('resource_upload') ) : the_row();
                  // display a sub field value
                  $docTitle = get_sub_field('document_title');
                  $docLink = get_sub_field('document_upload');
    
                  // set the image url
                  $image_url = $docLink;
    
                  // store the image ID in a var
                  $image_id = pippin_get_image_id($image_url);
    
                  // retrieve the thumbnail size of our image
                  $image_thumb = wp_get_attachment_image_src($image_id, 'medium');
              ?><li>
                  <a href="<?php echo $docLink; ?>" target="_blank">
                    <div class="thumbnail"><img src="<?php echo $image_thumb[0];?>"/></div>
                  </a>
                  <div class="doc-content">
                    <h2><?php echo $docTitle; ?></h2>
                    <h3><a href="<?php echo $docLink; ?>" target="_blank">Download</a></h3>
                  </div>
                </li><?php
                  endwhile;
               ?>
            </ul>

    Hi @mondererdesign,

    Thanks for posting your code here as I ran into the same exact issues as you! However I couldn’t get the PDF thumbnail to be displayed. It just show the default document icon no matter what PDF I upload. I’ve also set Return Value as File URL in Custom fields. Would you have any idea what could possibly went wrong?

    Appreciate your help.
    Thanks!

    Thread Starter mondererdesign

    (@mondererdesign)

    Hi @imstanleyyeo,

    I hope this helps further…

    Here are my settings for the PDF upload in ACF: https://screencast.com/t/jEUo7gpEx0h

    I got the code for my functions.php from here: https://pippinsplugins.com/retrieve-attachment-id-from-image-url/

    So I have the PDF Image Generator plugin installed as well, and make sure your hosting company support ImageMagick with Ghostscript, or else the PDF image won’t generate at all.

    Thanks for your reply, really appreciate your time. ??

    I have the same settings for the PDF upload in ACF as per your screencast. The function used is also exactly the same from your code into my functions.php. PDF Image Generator is also installed but this is still in my local dev env. I’m quite sure Imagemagick module and Ghostscript are installed if not, PDF Image Generator plugin cannot activate at all. Do you think it could be the version issue? What other possible issues in your opinion this might have caused? I’ve tried uploading a couple of PDFs, all of them couldn’t generate the first page as the thumbnail instead, the default document icon is shown as the preview.

    Thanks again and regards.

    Sorry, forgot to also mentioned that under Settings>PDF IMG Generator, “Use imageMagick with exec function” radio button is greyed out. Is this normal? My version of imageMagick is 6.9.5 by the way.

    I’ve also tried both “Generate images of PDFs that have no thumbnail” and “Regenerate and replace images of all PDFs” buttons under Image Generator Settings and both are unable to generate any images for the uploaded PDFs.

    Hope these info can help you point me in the right direction. Thanks again and sorry for my bad english.

    Thread Starter mondererdesign

    (@mondererdesign)

    @imstanleyyeo

    Here’s a screenshot of our PDF Image Generator settings, maybe this helps? https://screencast.com/t/fd5bjk4wDP4

    Thanks for sharing your screen, yes indeed it is helpful!

    Mine is exactly the opposite from yours where I cannot select “Use imageMagick with exec function” radio button because it is greyed out! I believe that could be my issue of the thumbnails not generating. Any settings that you know of, I might have missed out?

    I also reinstalled Ghostscript and ImageMagick with the latest version but it’s still the same.

    Thanks a lot!

    Anyone encounter this same issue and might have found a solution? Appreciate your help, thanks in advanced!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Not working with Advanced Custom Fields Repeater Fields’ is closed to new replies.