Home › Forums › General Issues › echo custom field content from most recent post in a certain category › Reply To: echo custom field content from most recent post in a certain category
Your code is a bit of a jumble mate. I would definitely take some time to comment, indent and prettify you code.
What you want to write is this:
<?php
if( is_home() )
{
$cat_id = 3; //the certain category ID
$posts = get_posts(array(
'posts_per_page' => 1,
'category__in' => array($cat_id)
));
// get recent
$recent = $posts[0];
// echo
echo get_field('hello-readers', $recent->ID)
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.