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 am trying to show a list of terms from my Job Category. I tried the following:

function job_listing_taxonomy_list( $taxonomy,$hide ) {
    $args = array('order'=>'ASC','hide_empty'=>$hide);
    $terms = get_terms( $taxonomy, $args );
    if ( $terms ) {
        printf( '<ul name="%s">', esc_attr( $taxonomy ) );
        foreach ( $terms as $term ) {
            printf( '<li><a href="http://example.com/?s=&'.$taxonomy.'=%s">%s</a></li>', esc_attr( $term->slug ), esc_html( $term->name ) );
        }
        print( '</ul>' );
    }
}

However, when I click the link of one of the terms that are generated, for example:

http://example.com/?s=&job_listing_category=finance

it is changed to:

http://example.com/?s?job_listing_category=finance

Why is the =& changing to a '?' ? I've spent a good half an hour combing Google and this site for answers, but I'm not entirely sure what to even look for! On a side note, I did have a Custom Post Type Permalink Rewrite plugin installed earlier which caused a Strict Standards error, but after disabling it (turns out I wasn't using it anyway), I now get this error....

Any suggestions?

Edit: I've tried replacing the & with &, but it didn't make a difference

share|improve this question
    
by "rewritten" I assume you mean "redirected to". you're using query string arguments, which are unrelated to rewrites. what is the purpose of the empty s argument? I am guessing that your theme or a plugin is producing this behavior, as a core bundled theme with no plugins does not produce the result you describe. –  Milo Dec 2 '13 at 16:38
    
If we're going to be pedantic, then yes, I mean "redirected to"! The link is actually a empty S argument from the original purpose of the function, which is for the search bar at the top of my site. Now that works perfectly, using an almost identical structure to the one shown above. The difference is that it uses <select> and <option> tags, and uses an $output.= variable for each tag. I am currently building this on the WP Job Manager plugin –  tristanojbacon Dec 2 '13 at 17:12
    
not being pedantic, just trying to clarify your perception of what's happening. rewrites parse incoming pretty url requests, and you mention the Custom Post Type Permalink Rewrite plugin - "rewrite" has a specific meaning in WordPress and neither of these things are related to your issue. but again, this is not the behavior of a vanilla install of WordPress, so you need to disable everything and switch to a core bundled theme, then re-enable things until you determine the source of this redirect. and the s argument is doing nothing here, so I'm not sure why you have it there. –  Milo Dec 2 '13 at 18:16
add comment

1 Answer

After taking @Milo 's comments into consideration, I removed the s= argument from the link, and it worked!

This is my final code:

function job_listing_taxonomy_list( $taxonomy,$hide ) {
    $args = array('order'=>'ASC','hide_empty'=>$hide);
    $terms = get_terms( $taxonomy, $args );
    if ( $terms ) {
        printf( '<ul name="%s">', esc_attr( $taxonomy ) );
        foreach ( $terms as $term ) {
            printf( '<li><a href="%s/?'.$taxonomy.'=%s">%s</a></li>', site_url() ,esc_attr( $term->slug ), esc_html( $term->name ) );
        }
        print( '</ul>' );
    }
}

The difference is that I removed the s= argument, and added site_url() as well so that I don't have to change it when the site is moved to the live server.

The only reason I had the s= there in the first place, was because I was adapting the search URL from my search bar, and so in my lack of understanding I assumed that it needed the s= there in order to function. Evidently not!

share|improve this answer
add comment

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.