0

i have 4 post and i displaying 2 post per page.

$ids = array('16085','16088','16083','16091');

$options = array(
        'post_type' => $post_type,
        'posts_per_page' => $posts_per_page,
        'paged'     => $paged,
        'meta_query' => $meta_query,
        'tax_query' => $tax_query,
        'post__in ' => $ids,
        'orderby' => 'post__in',
);
$get_properties = new WP_Query( $options ); 

i want to display post in specific order in given $ids array.

but it's not giving that array order.

2

OK, so you want to define posts order by yourself. WP_Query allows you to do that - you'll have to use orderby => post__in to achieve it. And that's what you do.

So why isn't it working? Because of a typo ;)

Ordering posts by post__in preserves post ID order given in the 'post__in' array. But you don't pass post__in param in your query (you pass post__in - additional space at the end).

$ids = array('16085','16088','16083','16091');

$options = array(
    'post_type' => $post_type,
    'posts_per_page' => $posts_per_page,
    'paged'     => $paged,
    'meta_query' => $meta_query,
    'tax_query' => $tax_query,
    'post__in ' => $ids, // <-- here is the additional space
    'orderby' => 'post__in',
);
$get_properties = new WP_Query( $options ); 

So this should work just fine:

$ids = array('16085','16088','16083','16091');

$options = array(
    'post_type' => $post_type,
    'posts_per_page' => $posts_per_page,
    'paged' => $paged,
    'meta_query' => $meta_query,
    'tax_query' => $tax_query,
    'post__in' => $ids, // <-- there is no space anymore in here
    'orderby' => 'post__in',
);
$get_properties = new WP_Query( $options ); 
0

Try this below code

$get_properties = new WP_Query( array( 'post_type' => 'page','posts_per_page' => $posts_per_page,'paged' => $paged,'meta_query' => $meta_query,'tax_query' => $tax_query, 'post__in' => array( 32, 30, 27, 45) ,'orderby' => 'post__in' )  );


echo "<pre>";print_r($get_properties);exit;

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.