• I haven’t been able to load the custom fields of my page template, there’s documentation about how to call Posts custom fields , but nothing about Pages, ?How you call these on a page?, do you HAVE to call them inside the loop? what if i have a text located on a certain place of the screen(not were the loop is located) and i want to show that custom field?.

Viewing 5 replies - 1 through 5 (of 5 total)
  • How you call these on a page?

    Exactly the same way that you call them in a post.

    do you HAVE to call them inside the loop?

    No – as long as you can pass a post or page id to the function, you should be able to use it anywhere.

    If you call the custom field routine within the loop using the standard structure of get_post_meta($post->ID, 'nameoffield', true) then it will be addressing the post’s ID from the loop.

    The way to use the page’s ID is to first save the ID in a variable before the loop begins (eg, at the top of your php add <?php $thispage = get_the_ID(); ?> ) and then within the loop you can get the custom field with get_post_meta($thispage, 'nameoffield', true)

    Another way of doing it, of course, would be to save all of the page’s custom fields into variables before the loop and then you won’t have to use get_post_meta within the loop itself, thus avoiding confusion if you’re also pulling in post custom fields too.

    Hope that helps

    Peter

    Thread Starter ulozilla

    (@ulozilla)

    Thanks Peter, that looks like a nice workaround

    Thread Starter ulozilla

    (@ulozilla)

    I’ve tried the example Peter mentioned, i can get the custom fields of the page but only using <?php the_meta();?> , i’ve saved the page id before the loop and then inserted the get_post_meta($thispage, 'nameoffield', true) code, but it’s not working, maybe i need something else to make it work? any tips?

    Thread Starter ulozilla

    (@ulozilla)

    it’s working now =) , thanks just had to add :

    <?php echo get_post_meta($thispage, 'nameoffield', true) ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pages Custom Fields’ is closed to new replies.