I think we can simplify it with:
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
$response = rest_do_request( $request );
$data = rest_get_server()->response_to_data( $response, true );
by using rest_do_request()
.
Related Posts:
- WP Rest API v2 return posts with specific tag
- JSON: schedule creation of json file
- Why use JSON API to display recent posts?
- How can I convert results of WP_Query (of Custom Post Type, with Custom Fields) to JavaScript?
- Querying A Post That Includes Two Taxonomies Using JSON Rest API
- How to use wp_query to post count by search term > group post count by date > convert to json. (ex. result 12-21-2020 – 343)
- Loop Performance > JSON files vs. WP_Query vs. REST API
- JSON – Create rest api endpoint for Advanced Custom Fields
- How to get more data of a post by wp_query
- WP query retrieve the src of attached image
- Custom Taxonomy in custom REST API search
- Simple Apex Charts with jQuery not working
- WP_Query orderby date not working
- Best way to detect if you are in a SINGLE POST page
- How to do a wp_query using “BETWEEN” with two meta_values?
- wp_query->max_num_pages always returns 0 on custom post type
- get_template_part in for loop
- How to display post from current Taxonomy in archive page?
- Getting attachments by meta value
- Display recent posts from the same category as current post in sidebar
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- WP_Query with LIKE in meta gives strange query
- WP_Query not working as expected for attachments and custom meta_query
- How to Get All Posts but the Private ones?
- WordPress custom search form with pre_get_posts not work
- Custom URl parameter
- order by multiple meta keys in pre_get_posts
- Order By Multiple Meta Fields
- WP_Query Performance Issues with meta_query
- WordPress: Keep order of query_posts list of post ID’s using post__in
- Advanced WP Query hogs the SQL server
- How to combine meta_query and post__in in WP_Query
- Is it faster to query records using $wpdb instead of Wp_Query?
- Display posts if specific country
- query user display_name failed in a custom mysql query foreach
- Meta box dropdown of custom posts
- Query posts by specific word on title
- Date and Category query with filter
- Get posts for which a custom field is not present, with get_posts
- Output an array of terms for a ‘tax_query’ => array()
- add active class based on permalink and url
- querying data via $wpdb and get_row
- Combining categories (Query posts with multiple taxonomy terms)
- Filtering out child category posts from parent category archive not working
- wp_update_post not working
- slow query – Search for Media Gallery
- WordPress has a list of reserved words, can I override them, to use one in a query string?
- WP_Query arguments order
- meta_query: check if number exists
- How to order WP_Query to group results?
- new WP_Query messes up pagination
- How to create custom query by keyword in post title?
- WP Query causing timeout
- get term id from term name
- Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute
- Use title of post as argument for query
- How can I comment comma-separated array values?
- Different Loop for tag pages?
- Orderby two meta fields not working
- Multiple Query_Posts
- WP_Query: attachment image in “full” size?
- Adding pagination to sub-wp_query within a singular post page
- How can I build a query that returns all attachments of a page and it’s children pages?
- How to add date_query to meta_query array
- Order by the first array within a meta_query
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- get_post_format is not returning standard
- Duplice post with standard WP loop – fixed by using query_posts() instead
- Get categories within specific term
- Exclude parent categories from recent posts list
- How can I query a radius of coordinates?
- custom excerpt is not being shown
- Filtering WP_Query based on wp_postmeta keys values
- meta_query only check if both value are set
- post_type not working when tag__in is present?
- How to create page that lists tags by initial letter?
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- WordPress: Cron locking and Queue
- 3 wp_query on one page with pagination for last query
- How to make the default WordPress search return borader results
- WP_Query shows all posts on single post pages
- Display Count of posts
- Optimize WP_Query
- Add a custom variable to query page object
- Dynamically name array in WordPress loop – add/get values
- Read more redirection problem
- Creating Custom Query
- Help in query for list links
- Multiple loops on index page with sticky post and pagination
- WP_Query issues with argument posts_per_page
- Search (Custom Form, Custom Search Result)
- Randomly display posts on a site hosted by WPEngine? [closed]
- tax_query not working properly with get_posts
- Elementor custom query
- Get access to all terms associated to each post that the wp_query loop displays
- I want to capture the last day’s (today) posts in a category in the numbered order in acf
- How do I have multiple metaqueries inside one wordpress query