0

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?

1 Answer 1

0

You can try this

$args = array( 
    'post_type' => 'Product',
    'orderby' => "name",
    'order'  => 'ASC',
    'posts_per_page' => -1,
    'post__in' => $productIds
);
1
  • name would be the slug, so he probably needs title instead.
    – vancoder
    Commented Feb 25, 2021 at 23:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.