WordPress.org

Ready to get started?Download WordPress

Forums

Using custom fields to display repeating text (4 posts)

  1. Rich Owings
    Member
    Posted 4 years ago #

    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?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

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

  3. Rich Owings
    Member
    Posted 4 years ago #

    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!

  4. Rich Owings
    Member
    Posted 4 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic