我最近发了一篇帖子,没有正确解释自己!再来一次,但要有更好的解释。
我需要“选择选项”更改query\\u帖子的顺序。我当前的代码是:
<select>
<option selected="selected">Select order of posts</option>
<option>Highest price</option><!-- hypercart_meta_price "order=DESC" -->
<option>lowest price</option><!-- hypercart_meta_price "order=ASC" -->
<option>Discount in%</option><!-- hypercart_meta_discount "order=DESC" -->
<option>Release Date</option><!-- date "order=DESC" -->
</select>
<?php $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1; ?>
<?php query_posts( \'post_type=products&orderby=meta_value_num&order=DESC&meta_key=hypercart_meta_discount&key=price&cat=\' .get_query_var(\'cat\')."&paged=".$paged); ?>
<?php get_template_part("loop-products"); ?>
我只需要知道如何使用“选择框”更改query\\u帖子,谢谢您的理解。拥抱
UPDATED MY ISSUE, 很抱歉给您带来不便。
SO网友:s_ha_dum
你的问题不是很详细。很难准确地计算出您正在做什么,但我假设您正在尝试按自定义meta对帖子进行排序meta_key
/meta_value
. 这就是公式(有注释,但基本上是从法典中摘取的):
$args = array(
\'post_type\' => \'your_post_type\', // I don\'t know what this is
\'meta_key\' => \'your_key\', // I don\'t know what this is
\'orderby\' => \'meta_value_num\', // only for numbers; use "meta_value" for alphanumerical keys
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'your_key\',
\'value\' => array(\'your_value\'), // can be more than one
\'compare\' => \'IN\', // see the Codex for other values
)
)
);
$query = new WP_Query($args);
参考
https://codex.wordpress.org/Class_Reference/WP_Query