• Resolved ersnyder

    (@ersnyder)


    I am trying to do what I would think would be fairly easy to accomplish, but apparently it is not (from what I have and have not found).

    I would like to use a custom field in a PAGE (in my page.php) but only display the Value of that custom field rather than displaying the default – Key: Value

    Any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m not exactly sure what you’re asking. To get a custom field value, you can do this:

    $key_name = get_post_custom_values($key = 'Key Name');
    echo $key_name[0];
    Thread Starter ersnyder

    (@ersnyder)

    That was it exactly, thank you!

    Does that solution have any security issues as stated in this post?

    https://www.ads-software.com/support/topic/114618?replies=7

    No, there aren’t any security issues with this.

    Hi there,
    Just to extend on this as its somewhat what I am after…I dont quite understand how to use the custom feilds but am pretty sure its what I need to do what I want to do.

    I have the one template but I want it to show different weather/images etc in the sidebar depending on the page (not post) that they are on.

    Could I add the code for a weather plugin to the sidebar and add the above code where the weather ID goes (then add the weather ID as the value of the custom field for that page setting). eg

    <?php if(function_exists(wp_forecast)) {
    wp_forecast( “<?php $key_name = get_post_custom_values($key = ‘Key Name’); echo $key_name[0]; ?>” );
    } ?>

    Any help at all would be appreciated!!!

    thanks

    Just an update..

    I am using

    <?php if(function_exists(wp_forecast)) {
    wp_forecast( “<?php $key_name = get_post_custom_values($key = ‘weather’); echo $key_name[0]; ?>” );
    } ?>

    and on my page I have added a Key called “weather” and given it the value of “A” which should return this code:

    <?php if(function_exists(wp_forecast)) {
    wp_forecast( “A” );
    } ?>

    However this does not seem to work as the weather area returns “Sorry, no valid weather data available.” instead of showing the weather for A

    I could see you doing this on a single post or page in the sidebar but definitely not on other pages (home, archives, etc.) unless you knew the specific post ID you wanted to get custom field value for. There are probably better solutions if you only want to use this in the sidebar.

    my home page isnt the blog, its a page set as the home page.. would that make a difference?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Field Value Only’ is closed to new replies.