| Server IP : 157.230.181.24 / Your IP : 216.73.217.11 Web Server : Apache/2.4.58 (Ubuntu) System : Linux conductive 6.8.0-117-generic #117-Ubuntu SMP PREEMPT_DYNAMIC Tue May 5 19:26:24 UTC 2026 x86_64 User : ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/vhosts/untold/app/admin/ |
Upload File : |
<?php
use Theme\Models\Article;
/**
* Article featured images
*/
add_action('rest_api_init', function () {
register_rest_field('article',
'featured_media_src',
[
'get_callback' => function ($object) {
$feat_img_array = wp_get_attachment_image_src($object['featured_media'], 'full');
return $feat_img_array[0];
},
'update_callback' => NULL,
'schema' => NULL,
]
);
});
/**
* Article timestamps
*/
add_action('rest_api_init', function () {
register_rest_field('article',
'date',
[
'get_callback' => function ($object) {
return get_the_date('F j, Y', $object['id']);
},
'update_callback' => NULL,
'schema' => NULL,
]
);
});
/**
* Article excerpt
*/
add_action('rest_api_init', function () {
register_rest_field('article',
'excerpt',
[
'get_callback' => function ($object) {
return get_the_excerpt($object['id']);
},
'update_callback' => NULL,
'schema' => NULL,
]
);
});
/**
* Article categories
*/
add_action('rest_api_init', function () {
register_rest_field('article',
'categories',
[
'get_callback' => function ($object) {
return get_the_terms($object['id'], 'category');
},
'update_callback' => NULL,
'schema' => NULL,
]
);
});
/**
* Related articles
*/
add_action('rest_api_init', function () {
register_rest_field('article',
'related',
[
'get_callback' => function ($object) {
$terms = get_the_terms($object['id'], 'category');
$ids = [];
if($terms) {
foreach($terms as $term) {
$ids[] = $term->term_id;
}
$articles = Article::getPostsRest([
'post_type' => 'article',
'post__not_in' => [$object['id']], // exclude self
'posts_per_page' => 4,
'tax_query' => [
[
'taxonomy' => 'category',
'field' => 'id',
'terms' => $ids,
],
],
]);
return $articles;
}
return NULL;
},
'update_callback' => NULL,
'schema' => NULL,
]
);
});