I have all my post id's in a specific array $productIds
. When I want to show only these posts, I do this query:
$args = array(
'post_type' => 'Product',
'orderby' => "post__in",
'posts_per_page' => -1,
'post__in' => $productIds
);
But this shows all the posts ordered from Z to A. So I've added an array in the orderby:
$args = array(
'post_type' => 'Product',
'orderby' => array (
'post__in' => $productIds,
'title' => 'ASC'
),
'posts_per_page' => -1
);
All the posts are shown, so not only the ones that are in the array $productIds
How do I order alphabetically (A->Z) and only show the ones that are in the array?
I have all my post id's in a specific array $productIds
. When I want to show only these posts, I do this query:
$args = array(
'post_type' => 'Product',
'orderby' => "post__in",
'posts_per_page' => -1,
'post__in' => $productIds
);
But this shows all the posts ordered from Z to A. So I've added an array in the orderby:
$args = array(
'post_type' => 'Product',
'orderby' => array (
'post__in' => $productIds,
'title' => 'ASC'
),
'posts_per_page' => -1
);
All the posts are shown, so not only the ones that are in the array $productIds
How do I order alphabetically (A->Z) and only show the ones that are in the array?
Share Improve this question asked Feb 25, 2021 at 11:15 DennisDennis 1358 bronze badges1 Answer
Reset to default 0You can try this
$args = array(
'post_type' => 'Product',
'orderby' => "name",
'order' => 'ASC',
'posts_per_page' => -1,
'post__in' => $productIds
);