admin管理员组文章数量:1022935
I have custom taxonomy, how can I add new element to taxonomy edit page in admin panel. For example, I have album as taxonomy and song as post type, my issue is that I want to show all songs that belong to current album when I edit album. Thanks.
I have custom taxonomy, how can I add new element to taxonomy edit page in admin panel. For example, I have album as taxonomy and song as post type, my issue is that I want to show all songs that belong to current album when I edit album. Thanks.
Share Improve this question asked May 19, 2017 at 1:09 Huy NguyenHuy Nguyen 134 bronze badges1 Answer
Reset to default 0Check that below code block, hope it will help you. Put it in your plugin or in theme's functions.php
file and it'll work. I tested it with category
taxonomy.
The code block-
// {$taxonomy}_edit_form_fields you should use
add_action( 'album_edit_form_fields', 'the_dramatist_add_custom_fields_to_taxonomy_edit_page', 10, 2 );
/**
* The function for rendering posts related to the term.
*
* @param object $tag Current taxonomy term object.
* @param string $taxonomy Current taxonomy slug.
*/
function the_dramatist_add_custom_fields_to_taxonomy_edit_page( $tag, $taxonomy) {
$songs_query = new WP_Query(
array(
'post_type' => 'post',
'post_per_page' => -1,
array(
'taxonomy' => 'album',
'field' => 'slug',
'terms' => $taxonomy // slug of the term
)
)
);
?>
<tr class="form-field term-description-wrap">
<th scope="row"><label for="description">Songs</label></th>
<td>
<table>
<?php
if( $songs_query->have_posts() ):
while( $songs_query->have_posts() ): $songs_query->the_post();
?>
<tr>
<td>
<h3><?php the_title()?></h3>
<p><?php the_content()?></p>
</td>
</tr>
<?php
endwhile;
endif;
?>
</table>
</td>
</tr>
<?php
wp_reset_postdata();
}
I have custom taxonomy, how can I add new element to taxonomy edit page in admin panel. For example, I have album as taxonomy and song as post type, my issue is that I want to show all songs that belong to current album when I edit album. Thanks.
I have custom taxonomy, how can I add new element to taxonomy edit page in admin panel. For example, I have album as taxonomy and song as post type, my issue is that I want to show all songs that belong to current album when I edit album. Thanks.
Share Improve this question asked May 19, 2017 at 1:09 Huy NguyenHuy Nguyen 134 bronze badges1 Answer
Reset to default 0Check that below code block, hope it will help you. Put it in your plugin or in theme's functions.php
file and it'll work. I tested it with category
taxonomy.
The code block-
// {$taxonomy}_edit_form_fields you should use
add_action( 'album_edit_form_fields', 'the_dramatist_add_custom_fields_to_taxonomy_edit_page', 10, 2 );
/**
* The function for rendering posts related to the term.
*
* @param object $tag Current taxonomy term object.
* @param string $taxonomy Current taxonomy slug.
*/
function the_dramatist_add_custom_fields_to_taxonomy_edit_page( $tag, $taxonomy) {
$songs_query = new WP_Query(
array(
'post_type' => 'post',
'post_per_page' => -1,
array(
'taxonomy' => 'album',
'field' => 'slug',
'terms' => $taxonomy // slug of the term
)
)
);
?>
<tr class="form-field term-description-wrap">
<th scope="row"><label for="description">Songs</label></th>
<td>
<table>
<?php
if( $songs_query->have_posts() ):
while( $songs_query->have_posts() ): $songs_query->the_post();
?>
<tr>
<td>
<h3><?php the_title()?></h3>
<p><?php the_content()?></p>
</td>
</tr>
<?php
endwhile;
endif;
?>
</table>
</td>
</tr>
<?php
wp_reset_postdata();
}
本文标签: How to customize taxonomy edit page
版权声明:本文标题:How to customize taxonomy edit page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745508732a2153730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论