Wp Rest Api Custom Endpoint for page subpages

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

WordPress JSON API returns normal site page in html. How do I get it to give me JSON?

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

How get Themes list via REST api?

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

WP Rest API convert permalink to post ID for fetch

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

ping_status in JSON REST API

According to WordPress Codex, pings tells Whether the current post is open for pings. In human words, A ping is a “this site has new content” notification that invites search engine bots to visit your blog. For more info, have a look at this blog article.

rest_post_query on multiple post types?

Define the callback as a named function and hook it separately for each post type. function wpse_299908_order_rest_query( $args ) { $args[‘orderby’] = ‘menu_order’; $args[‘order’] = ‘ASC’; return $args; } add_filter( ‘rest_post_query’, ‘wpse_299908_order_rest_query’ ); add_filter( ‘rest_page_query’, ‘wpse_299908_order_rest_query’ ); There’s no filter that automatically applies to all endpoints, likely for the same reason that you can’t query … Read more

WordPress Gutenberg get page template value when post updated?

So I found a solution. There are 4 hooks that can be used to accomplish this depending on the exact needs. The hooks are from wp-includes/meta.php in functions update_metadata() and add_metadata(). Hooks: update_postmeta updated_postmeta add_post_meta added_post_meta These are called at different states and from the names it is pretty self self explanatory. add_post_meta and update_postmeta … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)