Retrieve posts by tags with spaces
I’m trying to get posts by a tag (which, in this case, happens to be the post title). This works fine the when tag is a single word (e.g. ‘tag’), but when spaces (e.g. ‘tag spaced’) are introduced, it doesn’t work properly.
My solution thus far has been to do the following:
query_posts( array( 'tag' => str_replace( ' ', '-', get_the_title() ) ) );
However, I’m not certain this is a viable long-term solution, or even the correct one, at that.
Can anyone shed some light on this matter?
Thanks in advance!
- The topic ‘Retrieve posts by tags with spaces’ is closed to new replies.