I'm building a table with items in it. What I don't understand is the following:

When I type <td> <?php custom_get_terms('landschapspakket');?> </td>, it echoes the value of custom_get_terms('landschapspakket').

What I want to do is use some conditional logic over it to see which value it has, and then echo it. Instead it outputs it even before I type echo. Has it got something to do with the loop? How can I avoid this?


                <th>Be nr.</th>

            <?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(); ?>

                <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'])); ?>

                    <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; ?>

        <?php endwhile; endif; ?>


If the problem is in the function custom_get_terms(), I'll include the code:

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 {

Instead of doing: print $term->name; you need to return $term->name; so you can then use it for queries you could run on it.


I'm new here, so forgive me for posting an answer which is not really an answer, but I'm unable to coment on your question (an dI don't know why yet).

The data is printed/echoed because of this line in the custom_get_terms function

print $term->name;

If you want to work on/with the data/object you might want to change this line and return $term, for instance...?

// edit

I'm too slow, already answered.

  • This actually is an answer. Improve your code formatting, add a bit more code to put the solution into context, and add links to the Codex and or WordPress Trac source and it would be a decent one. – s_ha_dum Feb 20 '13 at 16:53
  • @s_ha_dum Thank you for your kind comment and the upvote. I will keep that in mind and work on improving my answers. – tfrommen Feb 20 '13 at 17:12
  • You don't know who upvoted you. Its anonymous. ;) – s_ha_dum Feb 20 '13 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.