Check 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();
}