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.

Get Post Meta

Featured Replies

Hiya,

 

I am trying to put some custom fields into events manager http://wordpress.org/plugins/event-organiser/

 

The problem that I am having is that I enter custom fields within the dashboard and I have been using this code within my template to bring them up:-

 

<?php the_meta(); ?>

This does work but it brings up loads of meta-keys that I don't want. I have asked the plugin owner who told me that I shouldn't use that code as it brings up everything, even for different plugins and to use this instead:-

 

$value = get_post_meta( get_the_ID(), 'my_field_key', true );

Problem is I have read the codex http://codex.wordpress.org/Function_Reference/get_post_meta and I just don't understand how to get it work. I am very new to this side of things with PHP, could someone help me out please.

 

Thanks in advance

Hi Charly :)

Me again, hope to help this time :p

 

Let's say in your WP page dashboard you enter a custom field called "Colour" and then a value for colour of "Blue".

 

Then in your theme files (where you want to show the field - within the loop) you put:

 

 

<?php

$value = get_post_meta($post->ID, 'colour', true);

if ( $value ) { ?>

<p>Colour: <?php echo $value ?></p>

 

<?php } else { } ?>

This will output Colour: Blue (or any other value you enter for the custom field).

 

This code checks if there is a value entered and if so, prints the value. If a value is not entered, you can specify something else in the PHP.

Hope that makes sense :)

Edited by teodora

  • Author

Teodora you are amazing, wish I was as smart as you!!

 

That's worked a treat and made total sense, sometimes all the terms confuse me.

 

How would I go about inserting a website hyperlink?

 

Thank you so much again :-)

For a link, I think something like this would work:

If you custom field is called "link_url" (for example):

 

To get image url:

<?php
        $link_url_value = get_post_meta($post->ID, 'link_url', true);
        if ( $link_url_value ) { ?> 
        <img src="<?php echo $link_url_value ?>" alt="" />

<?php } else { } ?>
 

To get link url:

 

<?php
        $link_url_value = get_post_meta($post->ID, 'link_url', true);
        if ( $link_url_value ) { ?> 
        <a href="<?php echo $link_url_value ?>">My link</a>

<?php } else { } ?>
 

You have to enter the full url beginning with http:// if it's an external link.

 

hth :)

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.