0

I have this snippet of PHP which looks at each post and displays the categories it is listed in on the archive page BUT I want to separate them either with
or in a OR even just with a comma and a space would work. Thanks

      <?php if ( ! $jobs ) : ?>
            <tr>
                <td colspan="6"><?php _e( 'You do not have any active   listings.', 'wp-job-manager' ); ?></td>
            </tr>
        <?php else : ?>
            <?php foreach ( $jobs as $job ) : ?>
                <tr>
                    <?php foreach ( $job_dashboard_columns as $key => $column ) : ?>
                        <td class="<?php echo esc_attr( $key ); ?>">
                            <?php if ('job_title' === $key ) : ?>
                                <?php if ( $job->post_status == 'publish' ) : ?>
                          <a href="<?php echo get_permalink( $job->ID ); ?>"><?php echo $job->post_title; ?></a><br> Job Status: 


<?php

$terms = wp_get_post_terms( $job->ID, 'job_listing_category' ); 

foreach ( $terms as $term ) {
  echo $term->name;
} 
?>

<?php else : ?>

                          <?php echo $job->post_title; ?> <small>  (<?php the_job_status( $job ); ?>)</small>
                            <?php endif; ?>
2
  • You're missing the if part of your code so it errors out. Commented Oct 28, 2016 at 7:54
  • Sorry didn't include it - I will edit the original post now Commented Oct 28, 2016 at 7:55

1 Answer 1

1

The foreach loop isn't needed. This will list out all job categories separated by a comma.

$terms  = wp_get_post_terms( $job->ID, 'job_listing_category' );

echo implode( ', ', wp_list_pluck( $terms, 'name' ) );

// Marketing, Sales, Finance, Support
2
  • Awesome that's the ticket, would I be able to add a <br> into that at all? Or is a comma the limit? Commented Oct 28, 2016 at 8:28
  • You can add whatever you want. Just replace the implode( ', ' with implode( '<br>'. Commented Oct 28, 2016 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.