Home › Forums › ACF PRO › ACF Load Field > Post Object > Render As Checkbox › Reply To: ACF Load Field > Post Object > Render As Checkbox
Did some additional searching and found this thread on Stack Overflow that showed what I was trying to accomplish. Copying it here, too:
It will require a little bit of code along with ACF
Add checkbox field (ex : your_field_name) and add following code in your functions.php file
function my_acf_load_field( $field )
{
global $post;
$field['choices'] = array();
wp_reset_query();
$query = new WP_Query(array(
'post_type' => 'your-custom-post-type',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
));
foreach($query->posts as $product_id=>$macthed_product){
$choices[$macthed_product->ID] = $macthed_product->post_title;
}
$field['choices'] = array();
if( is_array($choices) )
{
foreach( $choices as $key=>$choice )
{
$field['choices'][$key] = $choice;
}
}
wp_reset_query();
return $field;
}
add_filter('acf/load_field/name=your_field_name', 'my_acf_load_field');
use wp query parameters to filter posts.
Post id will be the checkbox value with title as label in metabox.
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.