wp query - Order posts inside bootstrap card columns

I have a bootstrap 4 card columns masonry like grid. I want to show six posts form my articles and I'm using a cust

I have a bootstrap 4 card columns masonry like grid. I want to show six posts form my articles and I'm using a custom query to retrieve the posts. All works fine, but the posts aren't showed with the order I want. I don't know if it's because the card columns bootstrap settings or because the wordpress query. Is there a simple way to order the loaded posts with a custom order?

here is the example of my wp query

<?php
$clients = ['199','168','86','291','113','229'];

$portfolio = new WP_Query(array(
    'post_type'     => 'post',
    'status'        => 'published',
  'category_name' => 'Portfolio',
    'posts_per_page'=> 6,
    'post__in' => $clients
));
?>

<div class="card-columns">
<?php if( $portfolio->have_posts() ): while( $portfolio->have_posts() ): $portfolio->the_post();  ?>
    <div class="card hide">
      <a href="<?php the_permalink(); ?>">
          <img class="card-img-top w-100" src="<?php the_post_thumbnail_url('full'); ?>" id="case-studies">
          <div class="overlay"><h4 class="text-center" id="client-name"><?php the_title(); ?></h4></div>
      </a>
    </div>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
</div>

I have a bootstrap 4 card columns masonry like grid. I want to show six posts form my articles and I'm using a custom query to retrieve the posts. All works fine, but the posts aren't showed with the order I want. I don't know if it's because the card columns bootstrap settings or because the wordpress query. Is there a simple way to order the loaded posts with a custom order?

here is the example of my wp query

<?php
$clients = ['199','168','86','291','113','229'];

$portfolio = new WP_Query(array(
    'post_type'     => 'post',
    'status'        => 'published',
  'category_name' => 'Portfolio',
    'posts_per_page'=> 6,
    'post__in' => $clients
));
?>

<div class="card-columns">
<?php if( $portfolio->have_posts() ): while( $portfolio->have_posts() ): $portfolio->the_post();  ?>
    <div class="card hide">
      <a href="<?php the_permalink(); ?>">
          <img class="card-img-top w-100" src="<?php the_post_thumbnail_url('full'); ?>" id="case-studies">
          <div class="overlay"><h4 class="text-center" id="client-name"><?php the_title(); ?></h4></div>
      </a>
    </div>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
</div>
Share Improve this question asked Apr 16, 2019 at 15:11 gogoDollgogoDoll 11 bronze badge 3
  • 1 Take a look at the order and orderby parameters of WP_Query. codex.wordpress/Class_Reference/… – MikeNGarrett Commented Apr 16, 2019 at 15:17
  • "I don't know if it's because the card columns bootstrap settings or because the wordpress query" figure that out and then you will know which path to investigate on sorting – RiddleMeThis Commented Apr 16, 2019 at 15:18
  • 1 @MikeNGarrett Solved by using the orderby param in WP_Query() Thanks for the suggestion – gogoDoll Commented Apr 16, 2019 at 16:13
Add a comment  | 

1 Answer 1

Reset to default 0

Take a look at the order and orderby parameters of WP_Query.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745583033a4634365.html

相关推荐

  • wp query - Order posts inside bootstrap card columns

    I have a bootstrap 4 card columns masonry like grid. I want to show six posts form my articles and I'm using a cust

    20小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信