admin管理员组文章数量:1327990
I want to create an Anime website. But I find it less effective if I have to manually copy & paste Anime information from MyAnimeList. So I want to create a system where users must enter the Anime ID from MyAnimeList and after that press the generate button, then automatically the desired Anime information will be filled in Metabox. Oh, my post_type
is anime
.
Here's the endpoint:
/v3/anime/{id}
And this is my Metabox:
<?php
/* Metabox Tweak */
if ( ! function_exists( 'rwmb_meta' ) ) {
function rwmb_meta( $key, $args = '', $post_id = null ) {
return false;
}
}
/* Anime Metabox */
function mal_metabox( $meta_boxes ) {
$prefix = 'mal_';
$meta_boxes[] = [
'id' => 'anime_info',
'title' => esc_html__( 'Anime Details' ),
'post_types' => [ 'anime' ],
'context' => 'advanced',
'priority' => 'high',
'autosave' => true,
'fields' => [
[
'id' => $prefix . 'title_japanese',
'type' => 'text',
'name' => esc_html__( 'Japanese' ),
'placeholder' => esc_html__( 'Japanese Title' ),
],
[
'id' => $prefix . 'title_english',
'type' => 'text',
'name' => esc_html__( 'English' ),
'placeholder' => esc_html__( 'English Title' ),
],
[
'id' => $prefix . 'title_synonyms',
'type' => 'text',
'name' => esc_html__( 'Synonmys' ),
'placeholder' => esc_html__( 'Synonyms Title' ),
],
[
'id' => $prefix . 'status',
'type' => 'text',
'name' => esc_html__( 'Status' ),
'placeholder' => esc_html__( 'Anime Status' ),
],
[
'id' => $prefix . 'types',
'type' => 'text',
'name' => esc_html__( 'Type' ),
'placeholder' => esc_html__( 'Anime Type' ),
],
[
'id' => $prefix . 'source',
'type' => 'text',
'name' => esc_html__( 'Source' ),
'placeholder' => esc_html__( 'Anime Source' ),
],
[
'id' => $prefix . 'duration',
'type' => 'text',
'name' => esc_html__( 'Duration' ),
'placeholder' => esc_html__( 'Anime Duration' ),
],
[
'id' => $prefix . 'episodes',
'type' => 'text',
'name' => esc_html__( 'Total Episodes' ),
'placeholder' => esc_html__( 'Total Episodes' ),
],
[
'id' => $prefix . 'seasons',
'type' => 'text',
'name' => esc_html__( 'Seasons' ),
'placeholder' => esc_html__( 'Seasons' ),
],
[
'id' => $prefix . 'studios',
'type' => 'text',
'name' => esc_html__( 'Studios' ),
'placeholder' => esc_html__( 'Studios' ),
],
[
'id' => $prefix . 'producers',
'type' => 'text',
'name' => esc_html__( 'Producers' ),
'placeholder' => esc_html__( 'Producers' ),
],
[
'id' => $prefix . 'releases',
'type' => 'text',
'name' => esc_html__( 'Releases' ),
'placeholder' => esc_html__( 'Release Date' ),
],
[
'id' => $prefix . 'genres',
'type' => 'text',
'name' => esc_html__( 'Genres' ),
'placeholder' => esc_html__( 'Genres' ),
],
[
'id' => $prefix . 'score',
'type' => 'text',
'name' => esc_html__( 'Score' ),
'placeholder' => esc_html__( 'Score' ),
],
[
'id' => $prefix . 'synopsis',
'type' => 'text_area',
'name' => esc_html__( 'Synopsis' ),
'placeholder' => esc_html__( 'Synopsis' ),
],
[
'id' => $prefix . 'poster',
'type' => 'file_input',
'name' => esc_html__( 'Poster' ),
'desc' => esc_html__( 'Anime Poster' ),
'max_file_uploads' => '1',
'max_status' => false,
],
],
];
return $meta_boxes;
}
add_filter('rwmb_meta_box', 'mal_metabox');
/* INPUT */
function generate_info($post) {
?>
<div class="rwmb-meta-box">
<div class="rwmb-field rwmb-text-wrapper">
<div class="rwmb-label">
<label for="anime-id">Jikan API</label>
</div>
<div class="rwmb-input ui-shortable">
<div class="rwmb-clone rwmb-text-clone">
<input size="30" type="text" id="anime-id" class="rwmb-text" name="anime-id" placeholder="Enter Anime ID"/>
</div>
<a class="button-primary" id="generate">Generate</a>
</div>
</div>
</div>
<?php
}
/* Show The Form */
function add_generate_info() {
add_metabox('generate_anime', 'Generate Info', 'generate_info', 'anime');
}
add_action('add_meta_boxes', 'add_generate_info');
本文标签: custom post typesHow to Grab Anime info using Jikan API and fill the value in Metabox
版权声明:本文标题:custom post types - How to Grab Anime info using Jikan API and fill the value in Metabox 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742247748a2440172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论