Home › Forums › General Issues › using the_field() in functions.php? › Reply To: using the_field() in functions.php?
Hi @chanshaw
Hmm… Please change the method query_posts()
and use get_posts()
instead and change your code to the following:
function load_highest_order_number() {
$args = array(
'meta_key' => 'order_number',
'cat' => 7);
$posts = get_posts($args);
foreach ($posts as $post):
echo get_field('order_number', $post->ID);
endforeach;
... //
}
Have a look at the documentation of get_posts() and query_posts() for more information on this. Here are the links:
https://codex.wordpress.org/Function_Reference/query_posts
https://codex.wordpress.org/Template_Tags/get_posts
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.