Ready to get started?Download WordPress


Custom fields on home page and blog page (6 posts)

  1. norbag
    Posted 3 years ago #

    Hi there,

    I have a static page set as my home page, and I´m struggling to display custom fields on this home page. Is there a different practice for including custom fields on a page that is set as the home pages? This is the code I´m using:

    <?php get_post_meta($post->ID, "punchline", true); ?>

    The "punchline" field is definitely defined in the admin panel, so what could be the problem then?


  2. esmi
    Forum Moderator
    Posted 3 years ago #

    What are you using to grab these posts in the home page's template file?

  3. pengbos
    Posted 3 years ago #

    Actually, you need to add a template for the home page, say home.php, which has a loop to query the posts. and in the loop, you will call <?php get_post_meta($post->ID, "punchline", true); ?> to get the custom field value for each post.

    You can have a look at some samples to learn. samples let you learn faster. If you don't mind, you can take a look at Aurelius theme. If you look at the home.php file, you will find how to code to get the custom values.

    or you can look in the codex document.

    good luck!!

  4. norbag
    Posted 3 years ago #

    I´m using a template for the home page. I´m using this code to grab the content of the page:

    <?php if(have_posts()) while(have_posts()) : the_post(); ?>

  5. Khanh
    Posted 3 years ago #

    try this http://wordpress.org/extend/plugins/fields/ you then can display custom field by putting a shortcode, e.g. [field key='punchline'] inside the post content without having to modify the template

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    That code will only display the content of the static home page itself (as added via Edit Page). Is that what you want or are you trying to display a number of posts?

    Also get_post_meta only grabs the custom field data - it doesn't display it. For that, you need <?php echo get_post_meta($post->ID, "punchline", true); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic