0

I'm using WP_Query to select a specific set of posts:

$args = array ( 'orderby'=>'rand', 'posts_per_page' => 1, 'category_name'=>'exercise', 'tag' => 'org:abc' );
$the_query = new WP_Query( $args );

but, when I run the query, it seems to be stripping the colon (:) in the tag name, so the query (when you output it) is searching for tag='orgabc', rather than 'org:abc'.

This also seems to happen with =, i.e. 'org=abc'

I've had to change my taxonomy as a result, but does anyone know why the colon is being stripped? is this a special character?

1 Answer 1

3

The tag parameter should be the tag's slug. If you look at your tag's archive URL (the view link when editing the tag), it won't have the colon in it, because that's not a legal character in a URL.

Your tag's name can still have the colon, and you can use the URLencoded version of a colon %3A in the slug if you want, though you will have to manually enter that in the slug field.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.