0
JSON APIを使用してWordPressブログのすべての投稿の抜粋を投稿するにはどうすればよいですか?Wordpress JSON apiで選択したアイテムを取得する
現在、私はhttps://www.example.com/wp-json/wp/v2/postsを使用していますが、多くのデータが返されてプロセス全体が遅くなります。選択したフィールドだけを取得できるURLはありますか?
JSON APIを使用してWordPressブログのすべての投稿の抜粋を投稿するにはどうすればよいですか?Wordpress JSON apiで選択したアイテムを取得する
現在、私はhttps://www.example.com/wp-json/wp/v2/postsを使用していますが、多くのデータが返されてプロセス全体が遅くなります。選択したフィールドだけを取得できるURLはありますか?
独自のAPIエンドポイントを作成したことがありますか? https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
あなたのエンドポイントがhttp://example.com/wp-json/myplugin/v1/post-titlesなっところ、このような何かはおそらくあなたのために働くだろう:
function my_awesome_func($data) {
$args = array(
'post_type' => 'post',
);
$query = new WP_Query($args);
$arr = array();
while ($query->have_posts()) {
$query->the_post();
$titles = get_the_title();
array_push($arr, $titles);
}
return $arr;
}
add_action('rest_api_init', function() {
register_rest_route('myplugin/v1', '/post-titles', array(
'methods' => 'GET',
'callback' => 'my_awesome_func',
));
});
私は、私たち自身のプラグインでこれを使用することはできますか?これにアクセスするための正確なURLは何でしょうか? –