• Hi, in my wordpress theme in functions.php file I have function like below:

    $posttitle = get_the_title($post->ID); // Display post title.
    
    $html .= '<div class="table">' .
    '<div class="name">'.$posttitle.'.</div>' .
    '</div>';

    I create custom-filed in my wordpress post as cfield = one.

    I tried to use this function to display of ‘cfield’ value but it doesn’t work:

    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'cfield', true);
    wp_reset_query();

    How to add my ‘cfield’ custom-field to this function below where “HERE” is:

    $html .= '<div class="table">' .
    '<div class="name">HERE '.$posttitle.'.</div>' .
    '</div>';
    • This topic was modified 5 years, 12 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s not enough context to reliably answer for functions.php code. What is your function hooked to? What data is your function collecting from the hook? If there’s a loop within your function, how is that setup?

Viewing 1 replies (of 1 total)

The topic ‘How to add custom-field in wordpress function.php file?’ is closed to new replies.