Home › Forums › ACF PRO › JSON (post_name) changes on every save › Reply To: JSON (post_name) changes on every save
That query could most definitely be causing part of you problem. There are 2 things, 1 is that I’m not sure it can work and get what you want, the other is that your not resetting post data.
function allPosts($field)
{
global $post; // without this you can't access $post-> below
$field['choices'] => array();
$query = new WP_Query(array(
'post_type' => 'any',
'posts_per_page' => -1,
));
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post(); // this alters the global $post value
// since your using the_post()
// may as well use $post here
$field['choices'][$post->ID] = $post->post_title;
}
}
// reset post data
wp_reset_postdata();
return $field;
}
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.