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'm looking for a way to query posts by id, and using a string as a parameter, instead of an array. Like this:

query_posts('p=153');

But I need to get multiple posts. For example with ID 153 and 154. How would I do that with a string as a parameter?

The reason that I'm using a string is because I'm generating that string with javascript and if I would do it otherwise it will get super complicated.

Any ideas?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You could convert the string to an array using the php explode function. So if you used a comma as your delimiter, you could pass the string '153,154,87' and that would and then use the explode function to convert it to

array(
[0]=>'153'
[1]=>'154'
[2]=>'87'
)

If you want to keep the p= you could use str_replace etc.

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.