检查下面的代码块,希望它能帮助您。将其放入插件或主题中functions.php
文件,它就会工作。我用category
分类学
代码块-
// {$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();
}