簡體   English   中英

循環中的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'
 );

可以使用代替芝加哥的變量來接受出發地的價值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM