pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 264 forks source link

Looping through a multiple files field doesn't return the files' urls #5852

Closed lhberg closed 4 years ago

lhberg commented 4 years ago

Issue Overview

I have a custom settings page with a file relationship field 'protocols' with multiple files allowed and get the list of the filenames when I loop through, but the files' urls are not returned; instead, it's the url of the post the shortcode is placed on.

Expected Behavior

The loop should return the files' urls (the files are PDFs)

According to my Slack thread with @jimtrue this should work: [each protocols] <a href="{@id,wp_get_attachment_url}">{@post_title}</a> [/each]

Template: https://codepen.io/lhberg/pen/RwRPgvQ Shortcode: [pods name="protocols_archive" template="Protocolarchive"] Pods setup: https://www.screencast.com/t/gGCBUBgm3 and https://www.screencast.com/t/2YsB2wvE5SX

Current Behavior

The loop returns the url of the post where the shortcode is placed on

I tried the same after clearing Pods cache with a fresh Pod with only one field and a fresh template on a fresh post, to no avail

Steps to Reproduce (for bugs)

Sorry, no live example, the site is not yet publicly accessible

1. 2. 3. 4.

Possible Solution

WordPress Environment

``` Copy and paste your System Details from **Pods Admin > Settings > Debug Information** in WordPress admin here. ```WordPress Version: 5.5.1 PHP Version: 7.4.11 MySQL Version: 5.6.49 Server Software: Apache Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0 Session Save Path: Session Save Path Exists: No Session Save Path Writeable: No Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: No Redis: No Object Cache: APC: No APCu: No Memcache: No Memcached: No Redis: No WPDB Prefix: wppr_ WP Multisite Mode: No WP Memory Limit: 512M Current Memory Usage: 166,514M Current Memory Usage (real): 170,000M Pods Network-Wide Activated: No Pods Install Location: /home/vltech/public_html/wp-content/plugins/pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: Beaver Builder Child Theme Currently Active Plugins: AddToAny Share Buttons: 1.7.42 Admin Columns Pro: 5.3.2 Admin Columns Pro - Pods: 1.5.1 Adminimize: 1.11.7 Admin Menu Editor Pro: 2.12.4 Advanced Editor Tools (previously TinyMCE Advanced): 5.5.1 Asgaros Forum: 1.15.8 Backup and Staging by WP Time Capsule: 1.21.25 Beaver Builder Plugin (Pro Version): 2.4.0.5 Beaver Themer: 1.3.2.3 Classic Editor: 1.6 Cookie Notice: 1.3.2 Duplicator: 1.3.38 Easy Updates Manager: 9.0.6 Easy WP SMTP: 1.4.1 Enable Media Replace: 3.4.2 Frontend Utilities for Asgaros Forum: 1.1.1 Gravity Forms: 2.4.20 Gravity Forms User Registration Add-On: 4.6 Gravity PDF: 5.3.2 GravityWP - CSS Selector: 1.0.1 Head, Footer and Post Injections: 3.2.1 Imsanity: 2.6.0 iThemes Security Pro: 6.7.1 Loco Translate: 2.4.3 Login With Ajax: 3.1.10 Maintenance: 3.97 MainWP Child: 4.1.2 MainWP Child Reports: 2.0.5 Media Library Folders for WordPress: 6.0.3 MetaSlider: 3.18.2 MetaSlider Schedule Slides: 1.0.5 Multiple Columns for Gravity Forms: 3.1.4 Page Links To: 3.3.4 PDF Thumbnails Premium: 1.4.2 Peter's Login Redirect: 2.9.7 Pods - Custom Content Types and Fields: 2.7.22 Pods Beaver Themer Add-On: 1.3.3 Pods Gravity Forms Add-On: 1.4.3 Post Expirator: 2.4.0.1 PowerPack for Beaver Builder: 2.11.0 Print, PDF & Email by PrintFriendly: 3.15.0 Say What?: 1.9.6 Simple 301 Redirects: 1.07 Smart Settings UI: 1.1.5 Styles & Layouts Gravity Forms: 4.2.9 Swift Performance: 2.2.1 TablePress: 1.12 TablePress Extension: Automatic URL conversion: 1.3 TablePress Extension: DataTables Buttons: 1.4 TablePress Extension: Remove Edit Link: 1.0 TablePress Extension: Responsive Tables: 1.7 Themer Templates for Beaver Themer: 1.3 Timed Content for Beaver Builder: 1.0.2 TinyMCE Custom Styles: 1.0.9 Ultimate Addons for Beaver Builder: 1.28.7 UpdraftPlus - Backup/Restore: 1.16.29 User Menus: 1.2.4 User Role Editor: 4.56.1 User Switching: 1.5.6 User Switching in Admin Bar: 1.2 WP-Optimize - Clean, Compress, Cache: 3.1.4 WP-ServerInfo: 1.66 WP-UserOnline: 2.87.5 WP Dashboard Notes: 1.0.10 WP Fulltext Search Pro: 2.36.125 WP Google Search: 1.0.9 WP Staging: 2.7.5 WP Statistics: 12.6.13 Yoast Duplicate Post: 3.2.6 Zeno Font Resizer: 1.7.5 Zeno Font Resizer Shortcode: 1.0

Pods Package Export (helpful!)

Copy and Paste the JSON Export from **Pods Admin, Migrate: Packages, Export** in WordPress admin here

{"meta":{"version":"2.7.22","build":1602429065},"pods":{"1569":{"id":1569,"name":"protocols_archive","label":"Dokumentenarchiv","description":"","type":"settings","storage":"none","object":"","alias":"","fields":{"protocols":{"id":1570,"name":"protocols","label":"Protokolle Mitgliederversammlung","description":"","help":"","class":"","type":"file","weight":0,"pick_object":"custom-simple","pick_val":"","sister_id":"","required":"0","file_format_type":"multi","file_uploader":"attachment","file_attachment_tab":"upload","file_edit_title":"0","file_show_edit_link":"1","file_linked":"0","file_limit":"0","file_restrict_filesize":"10MB","file_type":"any","file_field_template":"rows","file_add_button":"Add File","file_modal_title":"Attach a file","file_modal_add_button":"Add File","file_wp_gallery_output":"0","file_wp_gallery_link":"post","file_wp_gallery_columns":"1","file_wp_gallery_random_sort":"0","file_wp_gallery_size":"thumbnail","oembed_enabled_providers_hulucom":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0","file_allowed_extensions":"pdf"},"statuten_word_original":{"id":1571,"name":"statuten_word_original","label":"Statuten (Word-Original)","description":"","help":"","class":"","type":"file","weight":1,"pick_object":"custom-simple","pick_val":"","sister_id":"","required":"0","unique":"0","file_format_type":"single","file_uploader":"attachment","file_attachment_tab":"upload","file_edit_title":"0","file_show_edit_link":"1","file_linked":"0","file_limit":"0","file_restrict_filesize":"10MB","file_type":"any","file_field_template":"rows","file_add_button":"Add File","file_modal_title":"Attach a file","file_modal_add_button":"Add File","file_wp_gallery_output":"0","file_wp_gallery_link":"post","file_wp_gallery_columns":"1","file_wp_gallery_random_sort":"0","file_wp_gallery_size":"thumbnail","oembed_enabled_providers_hulucom":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"file_allowed_extensions":"pdf"}},"show_in_menu":1,"menu_name":"Dokumentenarchiv","menu_location":"top","ui_style":"settings","menu_position":"0","expirationdate_year":"2020","expirationdate_month":"10","expirationdate_day":"11","expirationdate_hour":"16","expirationdate_minute":"21","expirationdate_formcheck":"true","expirationdate_expiretype":"draft"}},"templates":{"Protocolarchive":{"id":1573,"name":"Protocolarchive","code":"

<span style=\"font-family:'Fedra Sans 2';font-size:20px;font-style:normal;font-weight:600\">Vereinsdokumente für den Vorstand<\/span><\/p>\r\n

<a href=\"{@statuten_wordoriginal}\" target=\"blank\">⇢ Statuten (.docx)<\/u><\/a><\/p>\r\n

 <\/p>\r\n

<span style=\"font-family:'Fedra Sans 2';font-size:16px;font-style:normal;font-weight:600\">Protokolle der Mitgliederversammlungen<\/span><\/p>\r\n

\r\n[each protokolle_mitgliederversammlung]\r\n <li class=\"protocols\"><a href=\"{@id,wp_get_attachmenturl}\" target=\"blank\">⇢ {@post_title} (.PDF)<\/u><\/a><\/li>\r\n[\/each]\r\n<\/p>","type":"template","slug":"dokumentenarchiv","options":{"_uabb_version":"1.28.6","_edit_lock":"1602427368:5","_edit_last":"5","swift-performance":"a:1:{s:14:\"include-styles\";a:1:{i:0;s:0:\"\";}}","_expiration-date-status":"saved","admin_only":"","restrict_capability":"","capability_allowed":"","pod_reference":"a:1:{s:3:\"pod\";s:0:\"\";}"}}}}

Workaround or Alternate Solution Until Bug is Addressed

Related Issues and/or PRs

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label Type: Bug to this issue, with a confidence of 0.80. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

JoryHogeveen commented 4 years ago

Hi @lhberg

The problem was that you were using lowercase for the ID param. The ID of an attachment (post) object is uppercase. The following would have worked: [each protocols] <a href="{@ID,wp_get_attachment_url}">{@post_title}</a> [/each]

However, I've created a patch to also support lowercase since we support that in most other cases as well.

I've also enhanced attachment support in each loops for cases when you've extended the attachments with a media Pod. In that case you can use the media fields and traversals.

Please test if you want! Patch: #5855

Cheers, Jory