Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wordpress Custom Fields php help!

Featured Replies

Hello,

 

I'm trying to use the Custom Fields feature of wordpress to output a download link underneath the actual post.

 

I want something like this in my single.php:

 

<div class="download-name"><?php GETNAME ?></div>
<div class="download-link"><a href="<?php GETVALUE ?>"><?php GETVALUE ?></a></div>

 

Which I want to output as:

 

Download Link 1: http://www.TheUrlHere.com

 

However, I'm a total newb in php coding so I would like to ask you if you know what code to put instead of GETNAME and GETVALUE to get the actual name and value.

 

I need to use this for all my posts so I can't use a fixed postid in single.php file.

 

FOR THOSE WHO ARE NOT FAMILIAR WITH CUSTOM FIELDS: http://codex.wordpress.org/Custom_Fields

 

Thank you!

Change the word "downloads" in the (' ') brackets to whatever you've used as your custom field name:

 

foreach(get_post_custom_values('downloads') as $key => $value)
echo "Download Link ".($key+1).": <a href=\"$value\" title=\"Download Link ".($key+1)."\">Download</a>";

 

Not 100% sure this will work for you, but give it a go...

  • Author

Change the word "downloads" in the (' ') brackets to whatever you've used as your custom field name:

 

foreach(get_post_custom_values('downloads') as $key => $value)
echo "Download Link ".($key+1).": <a href=\"$value\" title=\"Download Link ".($key+1)."\">Download</a>";

 

Not 100% sure this will work for you, but give it a go...

 

I tried your code but it gave me this error inside the page:

 

Warning: Invalid argument supplied for foreach() in /home/*****/public_html/*****/wp-content/themes/*****/single.php on line 42

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.