admin管理员组文章数量:1420073
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,
本文标签: Query posts only shows 1
版权声明:本文标题:Query posts only shows 1 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745320395a2653352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论