WP API V2 returning Invalid User ID
Wordfence blocks the User endpoint from the public. In settings there is a checkbox you can unselect to make it visible in the WP Rest API again.
Wordfence blocks the User endpoint from the public. In settings there is a checkbox you can unselect to make it visible in the WP Rest API again.
I made a shortcut to my image by adding it directly to the API response. //Add in functions.php, this hook is for my ‘regions’ post type add_action( ‘rest_api_init’, ‘create_api_posts_meta_field’ ); function create_api_posts_meta_field() { register_rest_field( ‘regions’, ‘group’, array( ‘get_callback’ => ‘get_post_meta_for_api’, ‘schema’ => null, ) ); } //Use the post ID to query the image and … Read more
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 }
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
There are two parts to the solution here. You need to use a JSON API custom controller In your custom controller, you’ll need to decide how to pass the meta_query data structure Depending on how robust you need this to be, you could use a variety of approaches. Here is the maximalist approach, that will … Read more
function checkApiAuth( $result ){ $yourEncryptAPIKey = $_GET[‘request’]; if( yourDecryptFn( $yourEncryptAPIKey ) === $realKey ): $result = true; else: $result = false; endif; return $result; } add_filter(‘rest_authentication_errors’, ‘checkApiAuth’);
From the documentation: According to the JetPack JSON API docs: By default, all metadata keys are allowed in the API, as long as they are not protected keys. Any metadata key that starts with _ is by default protected. Protected metadata keys can, however, be accessed and edited by users with the edit_post_meta (used for … Read more
Is it possible to do this with a rest query + filters? eg. http://wpsite.com/wp-json/wp/v2/posts?filter[only-permalinks] Yes, since 4.9.8 (see #43874) it’s possible to render only fields needed with the _fields parameter. Examples Render only the permalinks: https://example.com/wp-json/wp/v2/posts?_fields=link [ { link: “https://example.com/foo/” }, { link: “https://example.com/bar/” }, ] Render only the post IDs and permalinks: https://example.com/wp-json/wp/v2/posts?_fields=id,link [ … Read more
Depending on what kind of HTML you’re expecting, there are different tools you can use: esc_html() escapes entire HTML blocks so you don’t end up with breaking characters in your JSON object literals. esc_html_e() escapes (as above) and translates the string if you’re concerned about localization in that context. wp_kses() will parse the HTML string … Read more
You can actually find extensive documentation on wordpress.org. But let’s have a look at this particular example: https://demo.wp-api.org/wp-json/wp/v2/posts?per_page=5&tags=3 The 5 in there is the number of posts you want returned. The 3 is the id of the tag you want to limit the posts too. If you want to limit to a category use categories … Read more