admin管理员组文章数量:1122832
Is there any possibility to get featured post title and image using the JSON API.
I tried using this:
example/?json=the_post_thumbnails&count=3
But instead of recent posts, I get featured posts.
Is there any possibility to get featured post title and image using the JSON API.
I tried using this:
example.com/?json=the_post_thumbnails&count=3
But instead of recent posts, I get featured posts.
Share Improve this question edited May 31, 2014 at 1:10 kaiser 50.8k27 gold badges150 silver badges244 bronze badges asked May 30, 2014 at 22:37 warzone_fzwarzone_fz 1392 silver badges4 bronze badges 4- 1 Hello warzone_fz - welcome to the WordPress Development community! Questions regarding 3rd-party plugins and themes are considered off-topic for our community as it's rare that many if any members of our community has experience with such items - as such these questions tend to remain unanswered. Your question would be best asked in the official support channels for your plugin(s). Please read the on-topic and How to Ask sections of our help center for more information regarding what questions are a good fit for our community. – bosco Commented May 30, 2014 at 22:54
- 1 @boscho As this plugin is "future core", we (moderators) have (discussed and) decided that this plugin is on topic. – kaiser Commented May 31, 2014 at 1:09
- 2 @kaiser This question is related to another JSON API plugin, not the one slated for inclusion with WP core. It is related to: wordpress.org/plugins/json-api – Rachel Baker Commented May 31, 2014 at 3:56
- @RachelBaker Oh. Thanks! The OP will have to change the plugin to keep it on topic then. – kaiser Commented May 31, 2014 at 11:54
2 Answers
Reset to default 0I made a shortcut to my image by adding it directly to the API response.
//Add in functions.php, this hook is for my 'regions' post type
add_action( 'rest_api_init', 'create_api_posts_meta_field' );
function create_api_posts_meta_field() {
register_rest_field( 'regions', 'group', array(
'get_callback' => 'get_post_meta_for_api',
'schema' => null,
)
);
}
//Use the post ID to query the image and add it to your payload.
function get_post_meta_for_api( $object ) {
$post_id = $object['id'];
$post_meta = get_post_meta( $post_id );
$post_image = get_post_thumbnail_id( $post_id );
$post_meta["group_image"] = wp_get_attachment_image_src($post_image)[0];
//var_dump(wp_get_attachment_image($post_image)); die();
//Different image codex return different values, narrow in on what you want
return $post_meta;
}
Tty this one
jQuery.getJSON('/latest-post-as-json/', function(data) {
jQuery('#externalBlock').append('<h1>'+data.post_title+'</h1>');
jQuery('#externalBlock').append(data.post_content);
//etc
});
本文标签: How to get featured post title amp image using JSON API
版权声明:本文标题:How to get featured post title & image using JSON API? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283829a1927095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论