最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Multiple pagename WP Query

matteradmin9PV0评论

I wonder if I can use WP_Query() with multiple slug like p => array(1,2,3)

I have tried using pagename => array('accommodation','activities','restaurant') but pagename expects a string and doesn't accept arrays.


How do I Query multiple page using the page slug?

I wonder if I can use WP_Query() with multiple slug like p => array(1,2,3)

I have tried using pagename => array('accommodation','activities','restaurant') but pagename expects a string and doesn't accept arrays.


How do I Query multiple page using the page slug?

Share Improve this question asked Feb 19, 2019 at 7:41 Aftar FadilahAftar Fadilah 253 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

For multiple slugs, you can use post_name__in:

new WP_Query( array(
  'post_name__in' => array( 'accommodation','activities','restaurant' ),
) );

For multiple post IDs, you can use post__in:

new WP_Query( array(
  'post__in' => array( 1, 2, 3 ),
) );

You can check the Codex for more details.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far