612-293-8629 HELLO@THEMIGHTYMO.COM

Today I needed to put a custom field value into a variable that was being defined outside The Loop in functions.php. I had originally had the following code:

// This code DOES NOT work
$my_variable = get_post_meta($post->ID, 'my_custom_field_value', true);

The solution was the following:

// This code DOES work
$my_variable = get_post_meta(get_the_id(), 'my_custom_field_value', true);

Enjoy!

(Thanks Lasson!)

PHONE, EMAIL, TEXT

We love to communicate: phone, email, text, Facebook, Twitter, LinkedIn, you name it.

LOCATIONS

PAYMENTS ACCEPTED

Call Now

Enroll in Our Free Beginner WordPress Class by Email

Never feel powerless in WordPress again!  Become a WordPress superstar for free in only minutes a day!

Our Beginner WordPress Email Class is delivered to your inbox!

Learn More 

You Have Successfully Enrolled! Prepare For Amazing!