自定义WP CLI命令可将数据添加到WP REST API自定义字段

时间:2019-01-19 23:01:51

标签: wordpress api wp-cli

我正在使用WP CLI和WP REST API。

我要创建帖子,

$ wp post create --post_type=page --post_title='title-of-page' --post_status=publish

我需要通过我的wordpress主题中的functions.php文件添加的REST API中的字段:

function createField() {
  register_rest_field('page', 'rows', array(
      'get_callback' => function() {
        return "this part works.. kinda";
      }
  ));
}

enter image description here

该字段在API中显示正常。

问题:字段rows的值始终是相同的,因为它是通过functions.php设置的。我想在使用wp cli创建页面时(或在通过ID选择页面之后)通过终端设置(或覆盖,没关系)。

任何解决方案将不胜感激,而不必是wp cli。最好还是带终端!

0 个答案:

没有答案
相关问题