Sorry, 你不能在Guttenberg区块外使用它
but you can get same result every where in wp-admin by using the following solution,
有关详细信息,请访问WP Official Documentation
this.posts = {};
this.posts = new wp.api.models.Post();
this.posts.fetch().then( response => {
console.log(response);
});
下面是我如何在我的插件定制测试页面上使用它的一个示例,该页面是在古腾堡组件上开发的。
import {render,Component} from "@wordpress/element";
class TestingPage extends Component {
constructor() {
super( ...arguments );
// Solution - Start
this.posts = {};
this.posts = new wp.api.models.Post();
this.posts.fetch().then( response => {
console.log(response);
});
// Solution - End
}
render(
<TestingPage/>,
document.getElementById( \'testing-page\' )
);