Custom Fields: Display Key Only (7 posts)

  1. reevejgmailcom
    Posted 9 years ago #

    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.

  2. 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.

  3. toyfruit
    Posted 9 years ago #

    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.

  4. animator
    Posted 9 years ago #

    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;

  5. toyfruit
    Posted 9 years ago #

    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!

  6. tsguitar
    Posted 8 years ago #

    $key = $_GET['key'];

    Then just echo $key inside the loop.

  7. whooami
    Posted 8 years ago #

    $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.

Topic Closed

This topic has been closed to new replies.

About this Topic