用户如何对多个页面进行排序?

时间:2012-12-07 作者:user23898

我使用以下代码在多个页面上显示属性列表。我想让用户可以选择按自定义字段(可能是城市、房产名称或价格)对结果进行排序。我尝试添加\\u query\\u arg,但没有成功。有人有什么建议吗?我非常感谢您提供一个代码示例,因为我对PHP相当陌生。非常感谢你。

                <?php
                $wp_query = new WP_Query(array(
                    \'meta_query\' => array(
                        \'relation\' => \'AND\',
                        array(
                            \'key\' => \'listing_status\',
                            \'value\' => array(\'Active\', \'In Contract\'),
                        ),
                        array(
                            \'key\' => \'listing_type\',
                            \'value\' => \'For Lease\'
                        )
                    ),

                    \'paged\' => $paged,
                    \'orderby\' => \'title\',
                    \'order\' => \'ASC\'

                ));

                $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : -1;

                ?>

1 个回复
SO网友:Michael
                <p>Sort by: <a href="<?php echo str_replace((\'?\'.$_SERVER[\'QUERY_STRING\']), \'\', $_SERVER[\'REQUEST_URI\']).\'/?sort=name\'; ?>">Property Name</a> | <a href="<?php echo str_replace((\'?\'.$_SERVER[\'QUERY_STRING\']), \'\', $_SERVER[\'REQUEST_URI\']).\'/?sort=type\'; ?>">Property Type</a>

                <?php if($_GET[\'sort\'] == \'name\') $wp_query = new WP_Query(array( \'meta_query\' => array( \'relation\' => \'AND\', array( \'key\' => \'listing_status\', \'value\' => array(\'Active\', \'In Contract\'), ), array( \'key\' => \'listing_type\', \'value\' => \'For Sale\' ) ), \'paged\' => $paged, \'orderby\' => \'meta_value\', \'meta_key\' => \'property_name\', \'order\' => \'ASC\' )); ?>

                <?php if($_GET[\'sort\'] == \'type\') $wp_query = new WP_Query(array( \'meta_query\' => array( \'relation\' => \'AND\', array( \'key\' => \'listing_status\', \'value\' => array(\'Active\', \'In Contract\'), ), array( \'key\' => \'listing_type\', \'value\' => \'For Sale\' ) ), \'paged\' => $paged, \'orderby\' => \'meta_value\', \'meta_key\' => \'property_type\', \'order\' => \'ASC\' )); ?>
结束

相关推荐

Sorting by tag or category

以下是场景:用户单击一个标签,该标签会将他们带到所有带有该标签的帖子的列表。有数百篇帖子,因此用户需要一种方法来过滤这些帖子。问题是:如何构建一个下拉列表,用户可以在标记页面上选择按类别进行筛选。例如,按颜色类别过滤所有黄色标记。反之亦然。搜索颜色类别并按黄色标记过滤。