How to loop through JSON data in wordpress WP REST API

I managed to solve this and access the JSON data using a foreach loop: $json = lusso_posts(); #var_dump( $json ); #die(); foreach( $json as $post ) { $titles = $post->title; $images = $post->featured_image->guid; ?> <div class=”lusso-posts”> <div class=”image-container”><img src=”https://wordpress.stackexchange.com/questions/210472/<?php echo $images; ?>” /> </div> <h4><?php echo $titles; ?></h4> </div> <?php }

Disable external access to REST API Endpoint

I would suggest to not use WP REST API for this purpose, since it’s being used on homepage and not any remote app/service. The REST API is supposed to grant access to any already publicly available data to a remote developer. Since you’re not providing any public data but registering users from homepage, Ajax might … Read more

Get the list of enqueued/registered scripts for a specific post?

I’m not familiar with Gutenberg, but as you mentioned it as an example, I assume you didn’t mean “only” Gutenberg. The wp_enqeue_script() or wp_enqueue_style() functions do not accept arguments regarding posts or pages. The script are registered and rendered globally. If a script is output on certain posts only, then it has to be a … Read more

Include custom post meta value in fetched JSON

Two things to look at: 1) register_meta() 2) custom-fields support on post type. 1) register_meta You can register your custom post meta with show_in_rest => true to make it accessible via the api. Bottom of this page: Modifying Responses, provides the following example: <?php // The object type. For custom post types, this is ‘post’; … Read more

Override json encoding in rest api

It should be enough to add the content disposition field. But specifically it’s Content-Disposition not Content-disposition I would also add some validation to your filename parameter thats being passed to file_get_contents to ensure it exists and it’s valid. Else you might be vulnerable to directory traversal attacks or remote URL requests

Adding WordPress API Endpoint With Multiple Parameters

I have the same problem, i search on google finally with the help of the above answer i found out the solution. this may help others. $this->base = home register_rest_route( $namespace, “https://wordpress.stackexchange.com/” . $this->base . “https://wordpress.stackexchange.com/” . ‘products’ . “https://wordpress.stackexchange.com/”, array( array( ‘methods’ => WP_REST_Server::READABLE, ‘callback’ => array( $this, ‘rest_api_popular_products’), ), ) ); register_rest_route( $namespace, … Read more

Get loading state of wp data selector

Yes, it’s possible and you’d use wp.data.select( ‘core/data’ ).isResolving(). Example based on your code: const MyComponent = withSelect(select => { const { isResolving } = select( ‘core/data’ ); const query = { _fields: ‘id,name,slug’ }; return { terms: select(‘core’).getEntityRecords(“taxonomy”, “my_taxonomy”, query), isRequesting: isResolving( ‘core’, ‘getEntityRecords’, [ ‘taxonomy’, ‘my_taxonomy’, query ] ) }; })(props => { … Read more

How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?

I know it’s a bit far fetched, but might help. For anyone looking for WP REST API implementation with JWT, here’s our solution. Add it to your function.php add_action(‘rest_api_init’, ‘wp_rest_user_endpoints’); /** * Register a new user * * @param WP_REST_Request $request Full details about the request. * @return array $args. **/ function wp_rest_user_endpoints($request) { /** … Read more