Support

Account

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.