Multiple pagename WP Query

admin2025-06-03  3

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748891329a314582.html

最新回复(0)