• Imagine a text custom field in post-edit.php, function key = “function_name” and you want to print the value of this field in a specific area of the post

    I tryed with a fancy function, maybe something it’s usefull, and the rest is to fix

    // Get nome
    $nome = '<div class="nome">'. get_post_meta (  $post_id, $key = 'function_nome' ) .'</div>';
    
    function print_nome ($content) {
    
        if (is_singular('post')) {
            $content = $content . '<footer class="author_bio_section" >'.  $nome.'</footer>';
    
        }
        return $content;
    }
    • This topic was modified 1 year, 3 months ago by sacconi.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think there may be a misunderstanding over how to use get_post_meta.

    The “key” is just a simple string used to reference something set in the built-in WordPress Custom Fields interface under “Name” (as opposed to “Value”).

    Let’s say the key/Name is “name” and the value is “Leland” …it would be displayed on the frontend with the following PHP code placed within The Loop:

    <?php echo get_post_meta( get_the_ID(), 'name', true ); ?>

    And that code can be in a child theme to protect your customizations from parent theme updates.

    Does this help?

    Thread Starter sacconi

    (@sacconi)

    I have underscores as theme, I was told I dont have to create a child theme for it, is it correct?

    To tell the truth I have a custom plug in to display custom author fields (from edit user) in the posts, so I was trying to modify this plug in to display custom fields (from edit post) in the posts. Maybe should I create a copy-and-paste custom plug in but specific to display custom fields from post editor? eventually I can write here the plug in code

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘displaying a custom field value in the post’ is closed to new replies.