0

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?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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