2013-05-02 80 views

回答

1

WordPress拥有可以在查询中使用的order和orderby选项。

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

<?php 
$args = array('order' => 'ASC', 'orderby' => 'name'); 
$query = new WP_Query($args); 
while ($query->have_posts()) : $query->the_post(); 
// echo out the title, excerpt 
endwhile; 
?> 

你的示例页面使用GET变量。

?selSort = name_asc & txtKeyword = sdfsdf

所以,你需要创建一个形式方法= “GET” 是提交GET数据到当前页面。然后,使用PHP,您可以检查是否设置了任何GET数据(在本例中为selSort和txtKeyword)。如果其中任何一个已设置,请将它们放入您的查询中。然后,你可以修改查询类似于此:

<?php 
    $args = array('order' => $_GET['selSort'], 'orderby' => $_GET['txtKeyword']); 
    $query = new WP_Query($args); 
    while ($query->have_posts()) : $query->the_post(); 
    // echo out the title, excerpt 
    endwhile; 
    ?> 
+0

谢谢@Ankur - 这看起来像什么,我一直在试图找到!您能向我解释一下,在页面中插入日期和关键字搜索表单来实现这些选项的最佳方式是什么,就像我在问题中的例子中所做的那样? – 2013-05-03 12:24:47

+0

order和orderby都可以来自$ _GET。查看编辑了解更多信息。 – 2013-05-03 19:59:35

+0

谢谢@Ankur,这是最有帮助的。 – 2013-05-06 13:07:33