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?

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
    Feb 25 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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