Skip to main content
added 167 characters in body
Source Link

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/

This adds a path parameter and adjusts the query being made on the request accordingly:

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/

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/
deleted 4 characters in body
Source Link

This adds a path parameter and adjusts the query being made on the request accordingly:

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=/undersidapageslug/underundersidasubpageslug/

This adds a path parameter and adjusts the query being made on the request accordingly:

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=/undersida/underundersida/

This adds a path parameter and adjusts the query being made on the request accordingly:

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/
added 12 characters in body
Source Link

This adds a path parameter and adjusts the query being made on the request accordingly:

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);

}, 10, 2);

Allowing you to request a specific sub page like this:

.../wp-json/wp/v2/pages?path=/undersida/underundersida/

This adds a path parameter and adjusts the query being made on the request accordingly:

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=/undersida/underundersida/

This adds a path parameter and adjusts the query being made on the request accordingly:

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=/undersida/underundersida/
Source Link
Loading