Wordpress在循环中过滤WP_query值


Wordpress filter WP_query values in a loop

我正在为一家旅行社开发一个旅游网站。我试图让用户能够选择一个选项,如"选择你的出发"和过滤循环与所有可用的出发为所选的选项。例如:如果我想查询所有从芝加哥出发的航班,那么循环将只显示从芝加哥出发的航班!

<?php
  $args = array(
  'post_type'     => 'travel_packs',
  'order'         => 'ASC',
  );
  $the_query = new WP_Query( $args );
  if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>
//The loop:
<a href="<?php the_permalink(); ?>">
  Destination: <?php the_field('destination'); ?>
  Departing from:<?php the_field('departures'); ?>
  Price:<?php the_field('price'); ?>
</a>
<?php endwhile; endif; ?>

我想到了$_GET方法,但我不确定如何将其与the_field('departures');同化,但我想我偏离了轨道!

谢谢!

你应该试试这个

$args = array(
 'post_type'     => 'travel_packs',
 'order'         => 'ASC',
 'meta_key'   => 'departures',
 'meta_value'     => 'Chicago'
 );

在Chicago的位置,您可以使用接受出发值的变量。