I have an options page I have created for a post type which doesn't use a Guttenberg block, but I was wondering if inside that page I could somehow make use @wordpress/data
in order to retrieve posts with the below instead of using the REST API?
wp.data.select( 'core' ).getEntityRecords( 'postType', 'post' )
Right now, wp.data.select('core')
simply returns null
I have an options page I have created for a post type which doesn't use a Guttenberg block, but I was wondering if inside that page I could somehow make use @wordpress/data
in order to retrieve posts with the below instead of using the REST API?
wp.data.select( 'core' ).getEntityRecords( 'postType', 'post' )
Right now, wp.data.select('core')
simply returns null
1 Answer
Reset to default 1Sorry, you can not use it outside of Guttenberg block.
but you can get same result every where in wp-admin by using the following solution,
For Detail visit the WP Official Documentation
this.posts = {};
this.posts = new wp.api.models.Post();
this.posts.fetch().then( response => {
console.log(response);
});
The following is an example how i have used it on my pluging custom testing page which was developed on gutenberg components.
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' )
);
getEntityRecords
uses the REST API – Tom J Nowell ♦ Commented Jan 14, 2021 at 11:56