Support » Fixing WordPress » Using custom fields to display repeating text

  • Hi all,

    I write product reviews and the product name comes up repeatedly. I’ve created a custom field for this but am having problems getting it to display. I added this to functions.php:

    function get_custom_field_value($szKey, $bPrint = false) {
    	global $post;
    	$szValue = get_post_meta($post->ID, $szKey, true);
    	if ( $bPrint == false ) return $szValue; else echo $szValue;
    }

    (Source)

    Now here’s where I show off how little I know 😉 Can I just drop the code to call it into an html post, or do I need to use it in a template file?

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    (@esmi)

    Forum Moderator

    In a template file. PHP code will get displayed – rather than parsed – inside the post content.

    Thanks for taking the time to respond. Now I have to learn how to do a custom template file. Hey, it’s all good though — I’m learning!

    Hmm, after investigating developing a custom single.php file for my reviews category, I’m not sure this is possible.

    I wanted to use the custom field to grab the product name and use it in the title tag, various headers, and elsewhere within the post. Is there anyway to do that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using custom fields to display repeating text’ is closed to new replies.