Support » Fixing WordPress » Custom Fields: Display Key Only

  • How do I retrieve and display only the Key info from a Custom Field?


    The Custom Field is My Key: My Value. I want to display “My Key” on the page with no other information.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Does the key change? If so, then there’s no way to do it. You can display all the keys for any given post, but not one particular one if you don’t have any way to identify it. And displaying all of them is a bad idea, since WordPress uses several Custom Fields internally for various functions.

    The key is generally some fixed value that you define, the value is where you store the information you care about. It doesn’t really work too well the other way around.

    I don’t suppose anyone found a workaround for this? This is exactly what I’m trying to do. I want to have the key name AND the value displayed but I would like each one separate so I can style both items differently.

    I am not sure if this will work but i think i have done it somewhere in my code and it did.

    Inside the loop put this:

    $getmeta = get_post_meta($post_id=$post->ID, $key=’keyname’, $single=’true’);

    (keyname = the name of the key you want to show it’s value)

    then, right at the exact place (inside the loop too) you want value to appear put:

    echo $getmeta;

    Hi animator

    Thanks for the tip, but it doesn’t seem to have worked. I played around with a few variations but still can’t get the key name to show, I can only get the value.

    If anyone has any more suggestions, that would be great!

    $key = $_GET['key'];

    Then just echo $key inside the loop.




    $key = $_GET[‘key’]

    thats tremendously insecure, and bad advice.

    thats not the proper way to retrieve a variable that has been set previously. Thats how you would let the user assign what $key is.

    With that, I could pretty much run rampant on your install.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Fields: Display Key Only’ is closed to new replies.