Solve cors problem using rest api or ajax
Solve cors problem using rest api or ajax
Solve cors problem using rest api or ajax
WordPress Rest API only returns content when posttype has editor capability
A quick search through the WP-API source revealed where validate_callback is being used: wp-api/lib/infrastructure/class-wp-rest-request.php $valid_check = call_user_func( $arg[‘validate_callback’], $param, $this, $key ); In this case, $this is an instance of WP_Rest_Request – so there’s one. Now, for sanitize_callback: $this->params[ $type ][ $key ] = call_user_func( $attributes[‘args’][ $key ][‘sanitize_callback’], $value, $this, $key ); Same file, there’s … Read more
It works.. function list_subpages() { $data = array(); $request = array(); $id = 151; $subpages = get_pages( array( ‘child_of’ => $id, ‘sort_column’ => ‘menu_order’ ) ); if ( empty( $subpages ) ) { return null; } foreach ($subpages as $p) { $data[‘id’] = $p->ID; $data[‘title’] = $p->post_title; $data[‘img’] = wp_get_attachment_url( get_post_thumbnail_id($p->ID) ); $request[] = $data; … Read more
This will depend on the type of plugin you use for counting page hits. In general stats are being counted on front end, either by inserting some image or JS which generates a server hit on the stats server that will be counted (google analytics, wordpress.com stats) or by counting the hit and storing it … Read more
I’m likely doing it wrong, but when I form my requests for a WordPress installation at http://www.example.com/ like this: http://www.example.com/index.php?rest_route=/my/rest/route/here I end up getting proper responses back. I had a heck of a time figuring this out and ended up grokking a URL formatted like that in the HTML returned to me. I was expecting … Read more
It sounds like you’re on the right track as far as creating a custom post type. For the custom fields, you can either learn how to create your own plugin and create those yourself, or for a much easier experience, you could use a plugin such as Advanced Custom Fields that gives you a more … Read more
You can write your own endpoint and use wp_get_themes to get a list of themes via that. Here is a simple one: add_action( ‘rest_api_init’, function () { //Path to rest endpoint register_rest_route( ‘theme_API/v1’, ‘/get_theme_list/’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘theme_list_function’ ) ); }); // Our function to get the themes function theme_list_function(){ // Get … Read more
You’ll need to install a plugin to add authentication, by default it requires a cookie and a nonce token, but for CLI apps or PHP requests, you’ll want to install a basic auth plugin or use OAuth1/2
The core rewrite API does offer the function url_to_postid() (as mentioned by @stephen-sabatini) which can find a post ID from a URL. However it seems less than ideal to have to make a request up front just to determine the post ID… The REST API does not natively offer the ability to query by date … Read more