-1

I am trying to setup this repo Angular 2 Universal + WordPress REST API: https://github.com/jussikinnula/angular2-universal-wordpress

In the get function there is a search /wp-json/wp/v2/find?path= has that been removed from WordPres rest api? I trying to do a search on my web and get a 404 error

Path to my url

http://ecommerce-ux.london/wp-json/wp/v2/find?path=

Get request with find

 get(path: string) {
        if (path === "") {
            path = "header";
        }
        return this.apiService.get("/wp-json/wp/v2/find?path=" + path)
            .map(content => new Content(content))
            .do(content => this.setMeta(content))
            .catch(error => Observable.of(new Content({})));
    }
Chris Tarasovs
  • 703
  • 2
  • 21
  • 54

2 Answers2

0

Here in the Wordpress API changes page there is nothing outlining the "find" resource. Not sure where you might have got it from, but it wasn't removed recently. Maybe long time ago. What version of WP are you on?

Sedky A
  • 184
  • 2
  • 15
0

This adds a path parameter and adjusts the query being made on the request accordingly. The get_page_by_path function helps us retrieve the correct page in WP and we can then adjust the arguments sent to the query that runs on the /pages path in wp-json.

add_filter('rest_page_query', function ($args, $request){
  $path = $request->get_param('path');

  if (!empty($path)) {
    $pageByPath = get_page_by_path($path, OBJECT, 'page');

    // overwrite the page id with the page id by path
    $args['p'] = $pageByPath->ID;
  }

  return $args;
}, 10, 2);

Allowing you to request a specific sub page like this:

.../wp-json/wp/v2/pages?path=/pageslug/subpageslug/