• I want to display data from a custom field on a page and I have found that the following is one way to do it:
    <?php echo get_post_meta($post->ID, “myFieldName”, true) ?>
    This hasn’t worked and I think it’s because I’m not in the loop — so $post->ID doesn’t mean anything. The custom field data I want isn’t really from a post, per se, but from a static page. How can I display it on another page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • So write in the ID manually if you know which page specifically you want to pull data from..

    <?php echo get_post_meta( 999 , "myFieldName", true); ?>

    999 is an example value/id..

    Thread Starter akiryk

    (@akiryk)

    What if the data comes from a page — an About page? In other words, there isn’t a post ID because there isn’t a post… right? So my ID number isn’t quite so straightforward, I believe.

    A page is still the same, it just has a different post_type ..

    Essentially all post types are posts, it’s just the confusing naming scheme that makes it misleading, mainly related the blogging history of WordPress.

    I’m hoping with the introduction of custom post types, that over time the naming scheme for different content types will change (content type, or whatever), so it becomes less confusing..

    Your page is the same as a post as far as how it’s stored in the database, in the “posts” table, with a “post_title”, “post_content”, and a “post_type” and so on… essentially it’s still a type of “post” … (i hope you see what i’m getting at)..

    So to summarise, the code should work for pages to, unless there’s some hard-coded limitation in the function that i’m unaware of.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying custom field data from a page on another page’ is closed to new replies.