I have an array of ids:
var_dump($userPostsInternal);
-> string(13) "128537,128545"
Then I do
$args = array(
'post__in' => array($userPostsInternal),
'post_type' => 'post',
'posts_per_page' => -1,
);
$q = new WP_Query( $args );
foreach ( $q->posts as $post ) {
$title = $post->title;
echo $title;
}
But I only get 1 title. There are 2 articles and they do have the ids we see in the var_dump();
I even tried:
foreach ( $q->posts as $post ) {
$title = get_the_title();
echo $title;
But I still get one title only.
If I explode $userPostsInternal
I get array(2) { [0]=> string(6) "128537" [1]=> string(6) "128545" }
and no results at all
I have an array of ids:
var_dump($userPostsInternal);
-> string(13) "128537,128545"
Then I do
$args = array(
'post__in' => array($userPostsInternal),
'post_type' => 'post',
'posts_per_page' => -1,
);
$q = new WP_Query( $args );
foreach ( $q->posts as $post ) {
$title = $post->title;
echo $title;
}
But I only get 1 title. There are 2 articles and they do have the ids we see in the var_dump();
I even tried:
foreach ( $q->posts as $post ) {
$title = get_the_title();
echo $title;
But I still get one title only.
If I explode $userPostsInternal
I get array(2) { [0]=> string(6) "128537" [1]=> string(6) "128545" }
and no results at all
1 Answer
Reset to default 1OK this is the thing:
I used a query
$args = array(
'post__in' => array($userPostsInternal),
Taking the fact the following is a string
var_dump($userPostsInternal);
-> string(13) "128537,128545"
I thought declaring the array here would work
array($userPostsInternal)
But it's not, therefore thanks to a comment, suggesting me to explode $userPostsInternal
converting the string into an array, I then had to remove the array declaration, making the query like:
$args = array(
'post__in' => $userPostsInternal,