September 24, 201312 yr 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
September 24, 201312 yr Hi Charly Me again, hope to help this time 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 September 24, 201312 yr by teodora
September 25, 201312 yr 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 :-)
September 25, 201312 yr 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