Forums

Custom Fields Not Working (4 posts)

  1. mbond5
    Member
    Posted 1 year ago #

    My custom fields is not working just wondering if I'm doing something incorrect...

    This is the function in the 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;
    }

    And then this is how it looks on my category.php for where I'd like to put the custom function...

    <?php
         $key = 'sidecolumn';
         $meta_field = get_post_meta($post->ID, $key, $single = true);
         echo $meta_field;
    ?>

    Is there anything else I am missing?

    Thanks,

    Mike

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Not sure what your question is since you are not calling get_custom_field_value in category.php.

  3. mbond5
    Member
    Posted 1 year ago #

    It's not working nothing shows up when I put in sidecolum and then the text I want to go in the custom field then I hit publish and nothing for that field shows

  4. vtxyzzy
    Member
    Posted 1 year ago #

    I would suspect that $post->ID is not set. Try echoing out "ID:$post->ID" to be sure it has a value.

    I still don't understand what get_custom_field_value is for. You are not calling it, so it is not being used here.

Topic Closed

This topic has been closed to new replies.

About this Topic