php CPT'食谱'编辑器中的默认模板块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php CPT'食谱'编辑器中的默认模板块相关的知识,希望对你有一定的参考价值。

//add_action( 'init', 'set_default_RECIPE_blocks_template' );
//add_filter( 'register_post_type_args', 'set_default_RECIPE_blocks_template', 20, 2 );

add_filter( 'register_post_type_args', function( $args, $post_type ) {
  if( 'recipe' === $post_type && is_array( $args ) ){
    $args['template_lock'] = 'all';
    $args['template'] = [
      [
        'wpzoom-recipe-card/block-recipe-card',[
          'placeholder'=>'',
        ]
      ]
    ];
  }
  return $args;
}, 99, 2 );

/*
References:
* https://www.billerickson.net/gutenberg-block-templates/ - but was more for CORE PostTypes & as you register a CPT
* https://wp.zacgordon.com/2018/01/05/how-to-add-block-templates-to-your-wordpress-theme-or-plugin/ - set template after CPT was registered
*/

/* other blocks setting examples
      [
        // Example of including a core image block
        // Optional alignment setting        
        'core/image', [
          'align' => 'left',
        ]
      ],
      [
        // Example of including a core paragraph block        
        // Optional alignment placeholder setting         
        'core/paragraph', [
          'placeholder' => 'The only thing you can add',
          'align' => 'right',
        ]
      ],
      [
        // Example of including a core heading block
        // Optional alignment placeholder setting
        'core/heading', [
          'placeholder' => 'TEST Author...',
          'align' => 'left',
        ]
      ],
      [
        // Example of including a custom block        
        // Optional placeholder setting        
        'custom/your-blocks', [
          'placeholder' => 'Custom placeholder',
        ]
      ]
*/

以上是关于php CPT'食谱'编辑器中的默认模板块的主要内容,如果未能解决你的问题,请参考以下文章

错误:错误1022:无法写入;表'食谱'中的重复键

PHP:CRUD 应用程序有更新/编辑问题

PHP如何取二维数组中的某列的最大值和最小值?

php CPT中的自定义字段

php中已知数组键值怎么取得键名

在php中如何取键?