Skip Navigation

[Resolved] Repeating term field file type => how to display file title not entire file link

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user has a repeatable file field and he would like to display the filenames as links to download the files.

Solution:
Because this a term field, this needs to be built using a custom shortcode. Check this reply
https://toolset.com/forums/topic/repeating-term-field-file-type-how-to-display-file-title-not-entire-file-link/#post-1986687

100% of people find this useful.

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 5 replies, has 2 voices.

Last updated by felixM-3 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1984771
Screen Shot 2021-03-13 at 11.03.00.jpg

I created a repeating custom term field - file type - and try to display file title with link on a category page.

I try the following code:

[wpv-for-each termmeta="wpcf-ctg-files"]
[my_file_name file_url='[types termmeta="ctg-file" output="raw"][/types]']<br />
[/wpv-for-each]

... but unfortunately not work.

Please help me. Thanks

PS: i created a shortcode:

add_shortcode( 'my_file_name', 'my_file_name_func');
function my_file_name_func($atts) {
$urls = $atts['file_url'];
$fileparts = explode('/', $urls);
return end($fileparts);
}

The shortcode and wpv-for-each works well on custom field

#1984781

PS: i created a shortcode:

add_shortcode( 'my_file_name', 'my_file_name_func');
function my_file_name_func($atts) {
$urls = $atts['file_url'];
$fileparts = explode('/', $urls);
return end($fileparts);
}

The shortcode and wpv-for-each works well on custom field

#1985497

Hello and thank you for contacting the Toolset support.

The code that you shared seems correct to me, I don't see what's causing the issue. Would you like to reproduce this issue in one of our test sites and let me check it? If yes, you can log in to this test site using the following URL hidden link

As soon as the issue is reproduced, I'll log into the site and see what's causing the issue.

#1986491

Hi Jamal,

I configured a custom term group with a custom filed - files type and choos repeat - and i added to post category. After that i create a new archive template for post categories archive. Also i added the shortcode "my_file_name" and custom code for it.

I add 5 pdf file to category named "Test-Ctg-for-custom-repeating-field". The result display only 1 attachment, not 5 => hidden link

Thank you!

#1986687

Thank you!

I checked this with our 2nd Tier and he confirms that the wpv-for-each shortcode is meant to be used with posts and will not work with terms or users. So I built a custom shortcode that does the job:

add_shortcode( 'term_files', 'my_term_files_func' );
function my_term_files_func($atts){
  $atts = shortcode_atts( array(
    'field' => '',
  ), $atts );
  
  $field = $atts['field'];
  if ( ! $field ) return;
  
  $values = get_term_meta( get_queried_object_id(), $field, false );
  
  $out = "";
  foreach( $values as $value ){
    $out .= '<a href="' . $value . '" target="_blank">' . end( explode( '/', $value ) ) . '</a><br />';
  }
  
  return $out;
}

To be used like:

[term_files field="wpcf-tfrf"]

Check the results here hidden link
hidden link

#1991897

My issue is resolved now. Thank you!