I've always stated that I couldn't write to publish. I've always said that I just wrote the story that wanted to come out and then looked for a market that it fit. And that was true, and still is true--for a given value of "true", as fantasy author Terry Pratchett might say.
The thing is, I found that I enjoy the challenge of writing for themed anthologies. The writing critique group to which I subject myself, Southern Indiana Writers, has been publishing a themed anthology every year for about fifteen years. Granted, our themes are pretty elastic, so the one called WAY OUT WEST included stories from Western Australia and the West End of a midwestern city as well as an actual Western. But the exercise got me started on the notion of writing for a market.
Then I submitted to an anthology associated with a magazine which had bought two of my "write it THEN market it" stories. I felt confident that they would love another story from me. They didn't accept that one.
WHY NOT? So I did what everybody tells one to do: I bought a copy of the anthology and read the stories and tried to figure out what they accepted stories had that mine didn't have. (I sold the story someplace else, by the way, so ha!) The next year, when the reading period approached for that anthology, I had a story in my head wanting to come out and--guess what?--the story that WANTED to come out conformed to the ideals of the market, and I did sell that story to them.
Now, this post isn't about me selling stories. This post is about writing to the market. This post is about just having a market in mind when your story starts coalescing. If the story that comes out won't work for that market, look for another market, but there's no shame in bearing guidelines in mind and seeing if some truth and beauty can collect around it.
These days, "I could never write to a market" sounds like saying, "I could never buy my child clothes that fit her." Your child is the heart of your story. Everything else is clothing. The marketplace is the event the child is attending. Sometimes you can find clothing that fits AND is appropriate for a particular event and sometimes you have to clothe the child and then find someplace to take her. Hmmm....then we get into payment for your child, and I'm just not going there.... I hereby declare this metaphor at an end.