Support

Account

Home Forums Add-ons Repeater Field How to make File repeater

Solved

How to make File repeater

  • Hello and thank you for the wonderful acf!\

    We cant find a solution about how can we make a file repeater! and we have a project for subtitles running now!

    in the backend we have create the http://prntscr.com/9wbmsphttp://prntscr.com/9wbn2v
    in our post page we have upload this 2 files http://prntscr.com/9wbnrw
    and in our php file we have try many many different codes examples and more and we get “array” or simple text or nothing now we have try this

    <?php
    $repeater = get_field(‘file_repeater’);
    if( $repeater ): foreach( $repeater as $row ):
    //$file contains either a file array, url or ID depending on what you’ve set in the field settings.
    $file = $row[‘file_upload’];

    //Now you’re free to play around with $file 🙂
    endforeach; endif;
    ?>

    and also we got nothing http://www.subshunter.com/2016/01/23/the-pardon-2013/

    But maybe all that details are not the enough details to help me, so what we must do to make a file repeater (and if you can help us step by step we will appreciate very much!!!)

    Thank you very much!
    (and sorry for my English)

  • Try something like this

    
    if (have_rows('file_repeater')) {
      while (have_rows('file_repeater')) {
        the_row();
        $file = get_sub_field('file_upload');
        echo $file['url'],'<br />';
      }
    }
    
  • we have try this

    
    <?php 
    if (have_rows('file_repeater')) {
      while (have_rows('file_repeater')) {
        the_row();
        $file = get_sub_field('file_upload');
        echo $file['url'],'<br />';
      }
    }
    ?>
    
    

    and we get that http://prntscr.com/9wcw5p in landing page! so we need that urls to be links for someone can download them! how can we do that!

    Thank you very much

  • You just need to change the echo to a link and put the url in the href attribute.

    
    <?php 
    if (have_rows('file_repeater')) {
      while (have_rows('file_repeater')) {
        the_row();
        $file = get_sub_field('file_upload');
        ?>
          <a href="<?php echo $file['url']; ?>">Download the Document</a>
        <?php 
      }
    }
    ?>
    
  • Very close to what we need!! Thank you!

    we have use this

    
    <?php 
    if (have_rows('file_repeater')) {
      while (have_rows('file_repeater')) {
        the_row();
        $file = get_sub_field('file_upload');
        ?>
    	<br>
    
    		<img style="width:18px; height:10px;" src="http://www.subshunter.com/wp-content/uploads/2016/01/br.png" />
    		<span><?php echo $title; ?></span>
          	<a href="<?php echo $file['url']; ?>">Download the Document</a>
    		
        <?php 
      }
    }
    ?>
    

    and we get http://prntscr.com/9wmchy
    and we need to show the file name not the Download the Document!

    how can we change that to shows the file name Title?

    For example in this page we have 2 files

    1 and we must get: http://prntscr.com/9wme2s
    2: http://prntscr.com/9wmeqj

    How can we do that?

    Thank you very much again

  • Some of the basic stuff like this is explained in the file field documentation http://www.advancedcustomfields.com/resources/file/

    If you want to see everything that’s returned for the file try doing the following in your code where you’re getting the value

    
    $file = get_sub_field('file_upload');
    echo '<pre>'; print_r($file); echo '</pre>';
    

    Here is how you show the file name

    
    <?php 
    if (have_rows('file_repeater')) {
      while (have_rows('file_repeater')) {
        the_row();
        $file = get_sub_field('file_upload');
        ?>
    	<br>
    
    		<img style="width:18px; height:10px;" src="http://www.subshunter.com/wp-content/uploads/2016/01/br.png" />
    		<span><?php echo $title; ?></span>
          	<a href="<?php echo $file['url']; ?>"><?php echo $file['filename']</a>
    		
        <?php 
      }
    }
    ?>
    
  • Thanks you very much for you help! we used your code but something happen bad and shows error page so we used this and work

    
    <?php 
    if (have_rows('file_repeater')) {
      while (have_rows('file_repeater')) {
        the_row();
        $file = get_sub_field('file_upload');
        ?>
    	<br>
    
    		<img style="width:18px; height:10px;" src="http://www.subshunter.com/wp-content/uploads/2016/01/eng.png" /> <span>[English]</span>
    		<span><?php echo $title; ?></span>
          	
    		<a href="<?php echo $file['url']; ?>"><?php echo $file['filename']; ?></a>
    		
        <?php 
      }
    }
    
    ?>
    

    we dont know what happen wrong but with your instructions that worked like charm!! http://prntscr.com/9xcuth

    Thank you very very much again!! 🙂

  • Hello and thank you for everything!
    i have one more question and i hope have solution!

    We need here http://prntscr.com/a0xqjw to import a counter to shows how many clicks happen in each file! can we do that somehow?

    Thank you again!

  • That depends on the code for the counter I guess, not really an answer but you’d need to look into how it works and what code it requires. The best person to answer that would be the creator of that code.

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘How to make File repeater’ is closed to new replies.