Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4601

    I have added several custom fields to a post. I also checked that I could execute php code in the post for that user.

    If I use the <?php the_meta(); ?> it shows all the metas but if I try anything with a single field for example lets say I have one meta called: Location and the other Address and I try to display them within the post they do not show at all.

    Is there something in the template loop that blocks this from working?

    <?php echo get_post_meta($post->ID, 'Location', true); ?> should be working but there is no output for that query when Location is clearly there is I use <?php the_meta(); ?>

    Any ideas?

    #46925

    ok I think I found why you probably should add this to the functions.php of your themes

    I added `function get_custom_field($key, $echo = FALSE) {

    global $post;

    $custom_field = get_post_meta($post->ID, $key, true);

    if ($echo == FALSE) return $custom_field;

    echo $custom_field;

    }`

    and then called the meta to display using <?php get_custom_field('location', TRUE); ?>

    unless I am using an older version of a theme that didn t have it I would expect the wordpress query to display mets to work.

    Something to look into I guess. Can you confirm that only this code would work or is there any other reason why the metas can not be displayed unless you tweak the functions.php?

    I also tried to display custom fields in Brightbox and they are also being stripped and not displayed…just so you know

    #46926

    I think I just realized that you can only query certain data within the loop and not outside unless you use something like

    global $wp_query;

    #46927

    Yes exactly. Many functions require a loop like the_author, the_content, etc.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Calling custom fields within posts issue’ is closed to new replies.