Skip to content

Support Custom Post Types #1

@regenrek

Description

@regenrek

Hi,

I was looking for something like this but I would be good to support
not just posts.

I did some quick change to your plugin. Works for me but it surely needs some testing.

function add_custom_data() {
        // Register the post type fields

        $post_types = get_post_types( array( 'public' => true ), 'objects' );

        foreach($post_types as $post_type) {

            $post_type_name     = $post_type->name;
            $show_in_rest       = ( isset( $post_type->show_in_rest ) && $post_type->show_in_rest ) ? true : false;

            if($show_in_rest) {

                register_rest_field($post_type_name,
                    'acf_fields', array(
                        'get_callback' => array($this, 'get_custom_data'),
                        'update_callback' => array($this, 'update_custom_data'),
                        'schema' => null
                    )
                );

            }
        }


    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions