get_post_meta Does Not Work Within The Loop

UPDATE: Please disregard this blog post. Ryan Duff gave me a huge tip that my code was not written correctly. In the code below, note that I have the line written as follows:
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.

Posted in ,

The Mighty Mo! Design Co.

RSS From Toby’s Blog

  • WordPress Maintenance Checklist: Keep Your Site Running Smoothly
    Discover the essential tasks for effective WordPress maintenance and ensure your website runs smoothly and securely with our comprehensive guide.
  • Why We Don’t Automate Our WordPress Hosting Business
    There are some great platforms out there to automate your website hosting biz: But we don’t use any of them. Here’s why: Hosting companies only get worse over time. Over the years, I’ve hosted websites on a bunch of platforms: All of these hosting companies share one thing in common: Over time, they all got…
  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…

More posts from themightymo.com

Make WordPress Work for You: How to turn your self-hosted WordPress blog into a totally rocking Content Management System (CMS)

By | March 7, 2009

WordPress Presentation What we might cover How many people have a website or blog? Brainstorm ideas for websites.  What do you want your website to do? WordPress as a CMS Examples: GBSSA.org, TeamUpMn.org, Letronica.com (http://www.letronica.com/content/), cryns.com Switching WordPress from a Blog to a CMS Photo Gallery: http://www.cryns.com/category/photos/ Post by email iPhone Application Cool Plugins: Podpress…

Unsummit Minneapolis

By | March 7, 2009

Today I will be liveblogging from the Unsummit (un)conference in Minneapolis. So far, I have bumped into all sorts of superstars from the local blogging and online social media scene, which is always fun.  I am looking forward to attending: “Launching a Startup in Your Spare Time” “Getting Good Ideas When Ideas are Tough” UnPanel…

Mark Gason Papervision 3D Presentation at FlashMN

By | February 18, 2009

I am liveblogging from Mark Gason’s presentation at FlashMN. These are my notes. Check out Mark’s page of resources.  It contains links to tutorials as well as all sorts of other Papervision 3D-related stuff.  http://gasolicious.com/flashstuff/PV3D_presentation.html Swift 3D is better than Papervision 3D in some ways: – You can model in Swift 3D, but AutoCAD also…

RSS From Toby’s Blog

  • WordPress Maintenance Checklist: Keep Your Site Running Smoothly
    Discover the essential tasks for effective WordPress maintenance and ensure your website runs smoothly and securely with our comprehensive guide.
  • Why We Don’t Automate Our WordPress Hosting Business
    There are some great platforms out there to automate your website hosting biz: But we don’t use any of them. Here’s why: Hosting companies only get worse over time. Over the years, I’ve hosted websites on a bunch of platforms: All of these hosting companies share one thing in common: Over time, they all got…
  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…