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
How to style FacetWP checkbox hierarchy results using jQuery
How to fix SpinupWP ballooning disk space issue
A site we host on Digital Ocean recently went down. It took me a lot of troubleshooting and digging before realizing that the issue was that our disk space was maxed out on Digital Ocean. The site in question needs ~20gb of space, so our 50gb server should be plenty. But alas, there it was…
Google Removed Our Business Listing – How we restored our biz to the Map and got our reviews back.
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…