• Resolved mluzvdb

    (@mluzvdb)


    Hi, I’ve created a custom post type (projects) (based on posts) with the pods framework.

    I use the gutenberg editor with custom ACF blocks and have set a default block template for pages and posts using this code:

    $page_default_template = array(
    array( 'acf/content-block-entry-header-minimalistic' ),
    array( 'acf/content-block-text-introduction' ),
    array( 'acf/content-block-text-general' )
    );

    $post_type_object = get_post_type_object( 'post' );
    $post_type_object->template = $page_default_template;
    $post_type_object = get_post_type_object( 'page' );
    $post_type_object->template = $page_default_template;


    This works like a charm for pages and posts, but I cannot get this to work for my new custom post type. There seems no post_type_object for projects. When I do a var_dump of get_post_types() there is only the _pods_template post type, no other pods post types or projects post type.

    How can I apply the block template to my projects post type?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    This will work if the template is on an action and priority which occurs after the custom post types have been initialized. For example, on init at priority 20:

    <?php

    add_action(
    'init',
    function() {
    $block_template = [
    [
    'core/paragraph',
    [
    'placeholder' => implode(
    PHP_EOL,
    [
    '’Twas brillig, and the slithy toves',
    ' Did gyre and gimble in the wabe:',
    ]
    ),
    ],
    ],
    [
    'core/paragraph',
    [
    'placeholder' => implode(
    PHP_EOL,
    [
    'All mimsy were the borogoves,',
    ' And the mome raths outgrabe.',
    ]
    ),
    ],
    ],
    ];
    foreach( [ 'post', 'page', 'project' ] as $post_type ) {
    get_post_type_object( $post_type )->template = $block_template;
    }
    },
    20
    );

    …results in a default Block Editor with two paragraphs containing placeholder text on post types post, page, and project, where project is configured by Pods.

    Thread Starter mluzvdb

    (@mluzvdb)

    Thank you, the priority fixed it for me!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.