Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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

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 {
                 }
              unset($term);
            } 
    }
} 
share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
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. –  t f 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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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