Question

I have a custom post type called 'Jobs'. The custom post type has a custom taxonomy, called 'locations'.

On the jobs page, is to display the locations to which is job posting corresponds to. I.e one job might have positions in Shanghai and Beijing available.

To try to show this, I write the following -->

<?php  
    echo '<ul class="opp_location">';
    echo get_the_term_list( $post->ID, 'locations', '<li>', ',</li><li>', '</li>' );
    echo '</ul>';
?>

However, if the job posting only has one term, nothing outputs.

However, when I have two terms, the second term outputs.

If I have three terms, than still only the second term outputs.

I'm not quite sure what's going on here. How would I make it so that all the terms in the custom taxonomy that belong to this post show up?

Here's the taxonomy code in functions.php -->

add_action( 'init', 'register_taxonomy_locations' );

function register_taxonomy_locations() {

    $labels = array( 
        'name' => _x( 'Locations', 'locations' ),
        'singular_name' => _x( 'Location', 'locations' ),
        'search_items' => _x( 'Search Locations', 'locations' ),
        'popular_items' => _x( 'Popular Locations', 'locations' ),
        'all_items' => _x( 'All Locations', 'locations' ),
        'parent_item' => _x( 'Parent Location', 'locations' ),
        'parent_item_colon' => _x( 'Parent Location:', 'locations' ),
        'edit_item' => _x( 'Edit Location', 'locations' ),
        'update_item' => _x( 'Update Location', 'locations' ),
        'add_new_item' => _x( 'Add New Location', 'locations' ),
        'new_item_name' => _x( 'New Location', 'locations' ),
        'separate_items_with_commas' => _x( 'Separate locations with commas', 'locations' ),
        'add_or_remove_items' => _x( 'Add or remove locations', 'locations' ),
        'choose_from_most_used' => _x( 'Choose from the most used locations', 'locations' ),
        'menu_name' => _x( 'Locations', 'locations' ),
    );

    $args = array( 
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'show_admin_column' => true,
        'hierarchical' => true,

        'rewrite' => true,
        'query_var' => true
    );

    register_taxonomy( 'locations', array('job'), $args );
}
Was it helpful?

Solution

Ohp, it seems like the first 2 terms in the taxonomy were not recognized. I tried re-adding them, and that fixed it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top