0

I want to display 'state' in my custom post type 'job' Archive page. Now my archive page only have title and excerpt. Can you tell me how to modify this 'content-job.php file?

p.s. My post type is 'job', taxonomy is 'state'. California or New York will be term in the 'state' taxonomy. 'underscorefoundation' is themename.

<?php
/**
 * @package underscoresfoundation
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php the_title( sprintf( '<h1 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?>

        <?php if ( 'post' == get_post_type() ) : ?>
        <div class="entry-meta">
            <?php underscoresfoundation_posted_on(); ?>
             <?php the_terms( $post_id, $state, $before, $sep, $after ); ?> 
        </div><!-- .entry-meta -->
        <?php endif; ?>
    </header><!-- .entry-header -->
<?php if ( is_search() || is_archive()|| is_category() || is_tag() ) : // Only display Excerpts for Search ?>
        <div class="entry-summary">
            <?php the_excerpt(); ?>
        </div><!-- .entry-summary -->
        <?php else : ?>
    <div class="entry-content">
        <?php
            /* translators: %s: Name of current post */
            the_content( sprintf(
                __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'underscoresfoundation' ),
                the_title( '<span class="screen-reader-text">"', '"</span>', false )
            ) );
        ?>

        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'underscoresfoundation' ),
                'after'  => '</div>',
            ) );
        ?>
    </div><!-- .entry-content -->
    <?php endif; ?>

</article><!-- #post-## -->
  • 2
    $state should be 'state' - the former is an undefined variable with no value, the latter is a string with value "state". – TheDeadMedic Mar 9 '15 at 11:00
0

Use wp_get_object_terms function to get any taxonomy you want, category, tag, state, etc.

For example:

$terms = wp_get_object_terms(get_the_ID(), 'state');
$state = array_pop($terms);
echo $state->name;

This function is returning array of terms, so in case you only have one state, it will return array of one item in it.

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.