PHP code example of moxie-lean / wp-endpoints-collection

1. Go to this page and download the library: Download moxie-lean/wp-endpoints-collection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moxie-lean / wp-endpoints-collection example snippets




\Lean\Endpoints\Collection::init();

add_filter('ln_endpoints_collection_data', function( $data ){
  if ( isset( $data['pagination']['items'] ) && $data['pagination']['items'] === 0 ) {
    return [];
  } else {
    return $data;
  }
});

add_filter( 'ln_endpoints_collection_item', function($item, $the_post) {
      if ( $the_post->ID === 1 ) {
        return [
         'message' => 'Nothing here',
        ];
      } else {
        return $item;
      }
    }, 10, 2);;
json
wp-json/leean/v1/collection?posts_per_page=3&author=1
json
wp-json/leean/v1/collection?post_type[]=post&post_type[]=page