The p
parameter accepts a single integer value, not a string or array of integers.
You would want to use the post__in
parameter which allows for an array of post id’s. Just a few notes here:
-
You will need to check if you actually have a valid array of post ID’s before passing it to
post__in
. If an empty array is passed,WP_Query
fails epically in that it returns all posts regardless. So be very carefull with this -
post__in
will return sticky posts as well, so you would want to consider adding'ignore_sticky_posts' => 1
to your query args -
You will need to convert the string of post ID’s to an array using
wp_parse_id_list()
before passing the ID’s topost__in
You can probably try something like this:
$value = get_field( 'event_hotels', false );
// Check if we have a valid string
if ( $value ) {
$post_id_array = wp_parse_id_list( $value );
// Make sure we have a valid array of ID's
if ( $post_id_array ) {
$args = [
'post__in' => $post_id_array,
'ignore_sticky_posts' => 1,
// REST OF YOUR ARGS
];
$loop = new WP_Query( $args );
// Your loop
wp_reset_postdata(); // After your loop, VERY IMPORTANT
}
}