Skip to main content
added new code snippet
Source Link
mrwweb
  • 10.3k
  • 5
  • 40
  • 75

It sounds like what you need is a custom secondary loop, probably using WP_Query, that just queries for your single most recent post. Once you have that, you can use get_post_meta() to grab the custom meta from that post in a new loop.


Edit:

Alternately, you can use get_posts() to get the first post's ID and use that. Something like this:

$my_most_recent_post = get_posts( 'numberposts=1' );
$my_most_recent_post_id = $my_most_recent_post[0]->ID;
get_post_meta( $my_most_recent_post_id, 'my_custom_field', true );

It sounds like what you need is a custom secondary loop, probably using WP_Query, that just queries for your single most recent post. Once you have that, you can use get_post_meta() to grab the custom meta from that post in a new loop.

It sounds like what you need is a custom secondary loop, probably using WP_Query, that just queries for your single most recent post. Once you have that, you can use get_post_meta() to grab the custom meta from that post in a new loop.


Edit:

Alternately, you can use get_posts() to get the first post's ID and use that. Something like this:

$my_most_recent_post = get_posts( 'numberposts=1' );
$my_most_recent_post_id = $my_most_recent_post[0]->ID;
get_post_meta( $my_most_recent_post_id, 'my_custom_field', true );
Source Link
mrwweb
  • 10.3k
  • 5
  • 40
  • 75

It sounds like what you need is a custom secondary loop, probably using WP_Query, that just queries for your single most recent post. Once you have that, you can use get_post_meta() to grab the custom meta from that post in a new loop.