我正在建一张表,里面有一些项目。我不明白的是:
当我键入时<td> <?php custom_get_terms(\'landschapspakket\');?> </td>
, 它呼应了custom_get_terms(\'landschapspakket\')
.
我想做的是在它上面使用一些条件逻辑来查看它有哪些值,然后对其进行回应。相反,它甚至在我键入echo之前就输出了它。这和环路有关吗?我如何避免这种情况?
<table>
<tr>
<th>Landschapspakket</th>
<th>Be nr.</th>
<th>Gebiedscode</th>
<th>Gebruiksrecht</th>
<th>Grond</th>
<th>Aantal</th>
<th></th>
</tr>
<?php $query = new WP_Query(array(\'post_type\' => $current_posttype, \'posts_per_page\' =>\'-1\', \'post_status\' => array(\'publish\', \'pending\', \'draft\', \'private\'/* , \'trash\' */) ) ); ?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<tr>
<td><?php custom_get_terms(\'landschapspakket\');?></td>
<td><?php custom_get_terms(\'beheerseenheidnummer\');?></td>
<td><?php custom_get_terms(\'gebiedscode\');?></td>
<td><?php custom_get_terms(\'gebruiksrecht\');?></td>
<td><?php custom_get_terms(\'grond\');?></td>
<td><?php custom_get_terms(\'stuks\');?></td>
<?php $edit_post = add_query_arg(\'post\', get_the_ID(), get_permalink(429 + $_POST[\'_wp_http_referer\'])); ?>
<td>
<a href="<?php echo $edit_post; ?>">Bewerk</a>
<?php if( !(get_post_status() == \'trash\') ) : ?>
<a onclick="return confirm(\'Weet je zeker dat je <?php echo get_the_title() ?> wilt verwijderen?\')"href="<?php echo get_delete_post_link( get_the_ID() ); ?>">Verwijder</a>
<?php endif; ?>
</td>
</tr>
<?php endwhile; endif; ?>
</table>
如果功能有问题
custom_get_terms()
, 我将包括代码:
function custom_get_terms($taxonomy) {
// Get terms for post
$terms = get_the_terms( $post->ID , $taxonomy );
// Loop over each item since it\'s an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
if ( $term->name != null ) {
print $term->name ;
// Get rid of the other data stored in the object, since it\'s not needed
} else {
}
unset($term);
}
}
}