1

I'm trying to make a link to the file I uploaded with ACF so that it goes right to the pdf viewer from the Read More link, but I am getting an error here is the code

<div class="col-md-6">

           <h2><?php the_title(); ?></h2>

             <?php if( is_page('promotions') ) : ?>



                <?php

                  $args = array(
                    'post_type'     => 'news',
                    'category_name' => 'promotion',
                    'post_status'   => 'publish',
                    'post_per_page' => '6',
                    'order'         => 'DESC',
                    'orderby'       => 'date'

                    );

                   $query = new WP_Query ( $args );
              ?>





                <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

                  <?php 

                      $file = get_field('pdf_upload');

                      if( $file ): ?>
                  <?php endif; ?> 


                    <div class="news-flex">
                      <div class="pdf-img"><?php the_post_thumbnail( 'medium' ); ?></div>
                    <div class="brief-text">
                        <h3><?php the_title(); ?></h3>


                        <p><?php the_content(); ?><a href="<?php echo $file['url']; ?>" target="_blank">Read More</a></p>


                    </div>  
                  </div>

            <?php endwhile; endif; wp_reset_postdata(); ?>

          <?php endif; ?>

    </div>

Here is the error code....

Warning: Illegal string offset 'url' in F:\Work\Websites\lg.dev\wp-content\themes\lgver0.1\page-newspage.php on line 52 Call Stack #TimeMemoryFunctionLocation 10.0015175728{main}( )..\index.php:0 20.0017177664require( 'F:\Work\Websites\lg.dev\wp-blog-header.php' )..\index.php:17 30.401424356632require_once( 'F:\Work\Websites\lg.dev\wp-includes\template-loader.php' )..\wp-blog-header.php:16 40.411824514304include( 'F:\Work\Websites\lg.dev\wp-content\themes\lgver0.1\page-newspage.php' )..\template-loader.php:89 h" target="_blank">Read More

Reading it I thought it was looking for a template called wp-blog-header but no luck. I thought that putting the $file call field should go inside the begining of the loop so that it would call the file attached to that post. Am I on the right track at all?

  • What is the "Return Value" settings for the custom field? Make sure it is set to "File Array" – TheDeadMedic Feb 19 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.