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 have the following that builds a list of custom taxonomy(location) terms on the archive page for a custom post type. My issue is that when it builds the URL it is picking up the last post as part of the URL. Also the query argument I don't need but a straight write of the base URL and then /location/$location->slug. Is there a specific WP function to do this? Thanks for any guidance.

                             $page_link = get_permalink();
                             $locations = get_terms( 'location' );

                              $args = array();
                              $args['post_type'] = 'psc';
                              $args['paged'] = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                              if ( isset( $_GET['location'] ) ) {
                              $args['location'] = $_GET['location'];
    $page_link = add_query_arg( 'location', $_GET['location'], $page_link );

if ( is_array( $locations ) ) {
    echo '<ul>';
    foreach ( $locations as $location ) {
        echo '<li><a href="' . htmlentities( add_query_arg( 'location', $location->slug, $page_link ) ) . '">' . $location->name . '</a></li>';
    echo '</ul>';

query_posts( $args );
if ( have_posts() ){
    while ( have_posts() ) {
share|improve this question
add comment

Your Answer


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

Browse other questions tagged or ask your own question.