1

This question already has an answer here:

i am trying to get posts by multiple posts slugs, i can do this by passing post ids but I do not want to pass post ids i am looking for posts slug

Here is my code

$option = array(
'posts_per_page' => -1,
'post_type' => 'post',
'name' => 'berlin, frankfurt, munich, augsburg'
);

$new_query = new WP_Query($option);
if ($new_query->have_posts()) {
while ($new_query->have_posts()) {
$new_query->the_post();
/* my html stuff */
}
}

but it does not display anything but when i pass only "berlin" then queyr gives me correct results. it mean i only need to use post ids to get selected multiple posts ?

marked as duplicate by birgire, Pieter Goosen, TheDeadMedic, fuxia Jun 4 '16 at 14:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • When in doubt, it's always good to check the Codex on WP_Query. – birgire May 29 '16 at 14:13
4

Try to put your post slugs in an array for the post_name__in parameter:

'post_name__in' => [ 'berlin', 'frankfurt', 'munich', 'augsburg' ],

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