这是一个解决方案,我需要返回一个字符串数组。在数组()中传递字符串是不够的
<?php $arr = explode(\',\', $string); ?>
完整代码
<?php
$post_objects = get_sub_field(\'choose_blocks\');
$string = "";
if( $post_objects ): ?>
<?php foreach( $post_objects as $post_object):
$post_id = $post_object->ID;
$string .= $post_id.\',\';
endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php $string = rtrim($string, \',\'); ?>
// THIS IS THAT I NEED TO GET IT WORK
<?php $arr = explode(\',\', $string); ?>
<?php
$args = array(
\'post_type\'=>\'presentations\',
\'post_status\'=>\'publish\',
\'post__in\' => array( $string )
);
?>
<?php // the query
$all_presentations = new WP_Query($args); ?>
<?php if ( $all_presentations->have_posts() ) : ?>
<?php while ( $all_presentations->have_posts() ) : $all_presentations->the_post(); ?>
<?php get_template_part( \'includes/content\', get_post_format() ); ?>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<!-- do nothing -->
<?php endif; ?>
<?php endif; ?>