I am having the following errors:
Warning : array_map(): Argument #2 should be an array in...
Warning : implode(): Invalid arguments passed in wp-includes/class-wp-query.php on line 1918
On my php I am receiving a var from another page and I do:
$myId = $_POST['varPostId'];
$parts = explode(',', $myId);
And then I need to read that value
query_posts(array(
'post__in' => $myId
));
But I get the above errors.
if I do:
'post__in' => $parts
));
I get a blank page.
I tried using implode
$myId = $_POST['varPostId'];
$parts = implode(',', $myId);
And getting the value directly in the query
query_posts(array(
'post__in' => $_POST['varPostId']
));
$_POST['varPostId']
is a single value like 405
It seems that the value you're getting from the
POST
request is containing just a single post ID which should be an int but is possibly a string. You'll need to do some type and error checking. Something like the following should hopefully work. I seequery_posts
andpost__in
, I'm assuming WordPress is at play here?To follow up on why
explode
isn't appropriate here, it's used to convert a string, usually something like this:Into an array with multiple items like the following:
But you it seems that you don't have a comma separated string of post ids, you just have the one so it's best not used here.
As already stated in the comments,
explode
takes a string and splits it into an array of items.implode
does the opposite. It takes an array and condenses it down into a string.So you could have something such as: