PHP code example of elvishp2006 / carbon-field-rest-api-select

1. Go to this page and download the library: Download elvishp2006/carbon-field-rest-api-select 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/ */

    

elvishp2006 / carbon-field-rest-api-select example snippets


Field::make( 'rest_api_select', 'id', __( 'Post' ) )
    ->set_endpoint_label_path( 'title.rendered' ) // Default: 'title.rendered'
    ->set_endpoint_value_path( 'id' )             // Default 'id'
    ->set_endpoint_search_param( 'search' )       // Default 'search'
    ->set_endpoint_params(
        [
            'per_page' => 20,
            'orderby'  => 'relevance',
        ]
    )
    ->set_endpoint( rest_url( 'wp/v2/posts' ) )