get_post_meta(post->ID, ‘custom_field_value’, true);
When you add the fancy dollar sign in front of “post->ID” like so “$post->ID”, the problem is fixed. Chalk it up to a late night bonehead move on my part, I guess. 🙂
I ran into a problem this morning. I was trying to use get_post_meta() within the loop and was unable to return the custom field value. The solution was to use “get_the_id()” rather than “post->ID” as shown below.
$my_query = new WP_Query('showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); get_post_meta(get_the_id(), 'custom_field_value', true); // This works! get_post_meta(post->ID, 'custom_field_value', true); // This DOES NOT work! endwhile; Thanks to this post for providing the solution.
More posts from themightymo.com
I was about to send an email to a potential customer pointing them to our 5-star Google Reviews via our Google Business profile (e.g. the Google Map), hoping this added information about our customers’ past experiences might help me close a deal. But when I checked the Google Reviews link, it was down. And after…
Cloudways Off-Site Backup Pricing Calculator: The Ultimate Cost Guide
I’ve had a couple of scenarios where I’ve needed to block a specific domain from filling out Gravity Forms on my WordPress site. Today I needed to block spammy “mailinator.com” submissions from a contact form. The solution was simple: Install and configure the Gravity Forms Email Blacklist plugin. In a few minutes – all done!