Home › Forums › General Issues › Populate ACF select field\'s choices with published WooCommerce Products › Reply To: Populate ACF select field\'s choices with published WooCommerce Products
To populate the choices you need to do a query to get all of the products. I’m not including everything from the page you posted, just the query
$choices = array();
$products = new WP_Query(array(
'post_type' => 'product',
'post_per_page' => -1,
'orderby' => 'post_title',
'order' => 'ASC'
));
if ($products->have_posts()) {
global $post;
while ($products->have_posts()) {
$products->the_post();
$choices[$post->ID] = $post->post_title;
}
wp_reset_postdata();
}
$field['choices'] = $choices;
for more information see https://codex.wordpress.org/Class_Reference/WP_Query
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.