• Resolved florryone

    (@florryone)


    Hello,

    I am trying to read out a value from a custom field inside the functions php.
    The code worked fine in the index.php but stopped working when I tried to put it in the functions php. To my surprise “echo get_post_meta($post->ID, ‘link’, true);” did not return a value. So I am wondering if the use of get_post_meta() is possible inside a function. If there are other ways to find out if there is a custom field inside a function please let me know.

    Thanks,

    This is what I have so far in functions.php with custom field id name ‘link’…

    <?php
    
    function s_the_title(){
    $var = get_post_meta($post->ID, 'link', true);
    if ($var == '')
    {
    $field_value = get_permalink();
    } else {
    $field_value = $var;
    }
    //
    	echo '<a href="';
    	echo $field_value;
    	echo '" rel="bookmark" title="Find out more about '; the_title();
    	echo '">';
    	echo the_title();
    	echo '</a>';
    }
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • function s_the_title(){
    global $post;
    Thread Starter florryone

    (@florryone)

    yep that worked fine ?? many thanks…

    Just want to say…
    THANK YOU !!!

    I was trying to get a function set up to display a post title differently if it linked externally… had the code spot on, I knew it… but it wasn’t working. Duh.

    And I remembered to add it to my dynamic post title font size due to length functional thingy too. Woo!

    I had the same issue as florryone this solved the problem: THANK YOU !!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘using get_post_meta() inside functions.php does not work why?…’ is closed to new replies.