Title: Sort Query Posts
Author: Tubal
Published: <strong>2011 年 1 月 15 日</strong>
Last modified: 2012 年 9 月 4 日

---

搜尋外掛

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

![](https://s.w.org/plugins/geopattern-icon/sort-query-posts.svg)

# Sort Query Posts

 由 [Tubal](https://profiles.wordpress.org/tubal/) 開發

[下載](https://downloads.wordpress.org/plugin/sort-query-posts.1.1.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/sort-query-posts/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/sort-query-posts/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/sort-query-posts/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/sort-query-posts/#developers)

 [技術支援](https://wordpress.org/support/plugin/sort-query-posts/)

## 外掛說明

A really simple and lightweight plugin (73 lines of code – comments included) to
sort posts on-the-fly without making a new query to the database (improves performance).

#### Features:

 * Supports **all `order_by` and `order` values of the [query_posts function](https://codex.wordpress.org/Function_Reference/query_posts#Orderby_Parameters)**
   except `meta_value` and `meta_value_num` (which require a database query).
 * Supports **changing the order of all types of posts**, including custom post 
   type posts and custom post type “archive” posts.

#### Documentation

This plugin adds the function `sort_query_posts_by(string $order_by [, string $order])`
to the global context.
 The second `$order` parameter is optional. Its default value
is `asc` (ascending order).

**Call this function before [the loop](https://codex.wordpress.org/The_Loop) to 
change how posts are ordered.**
 After calling this function you can show the posts
as you normally would.

You can sort posts by:

 * author
 * comment_count
 * date
 * id
 * menu_order
 * modified
 * parent
 * title

This is specially useful in two cases:

 * When you need to reorder the posts returned by the query that WordPress creates
   from your given URL. Custom post type “archive” posts are a great example of 
   this case.
 * When you need the posts returned by your customized query (e.g. `query_posts()`)
   to be shown more than once on the same page and ordered differently.

**Examples:**

    ```
    <?php sort_query_posts_by('title', 'desc'); ?>
    ```

The example above will sort posts by their title in descending order without making
a new query to the database.
 This way sorting is performance friendly.

    ```
    <?php sort_query_posts_by('ID'); ?>
    ```

The example above will sort posts by their ID in ascending order.

    ```
    <?php sort_query_posts_by('rand'); ?>
    ```

The example above will sort posts randomly. When sorting randomly `$order` is ignored.

Plugin developed by Túbal Martín at [www.margenn.com](http://www.margenn.com).

## 安裝方式

 1. Upload `sort-query-posts` folder to the `/wp-content/plugins/` directory
 2. Activate the plugin through the ‘Plugins’ menu in WordPress
 3. Use the added function `sort_query_posts_by` after any wordpress query and your
    posts will be sorted to your needs.

## 使用者評論

這個外掛目前沒有任何使用者評論。

## 參與者及開發者

以下人員參與了開源軟體〈Sort Query Posts〉的開發相關工作。

參與者

 *   [ Tubal ](https://profiles.wordpress.org/tubal/)

[將〈Sort Query Posts〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/sort-query-posts)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/sort-query-posts/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/sort-query-posts/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/sort-query-posts/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/sort-query-posts/)。

## 變更記錄

#### 1.1

 * Code refactored for improved performance. Updating is recommended.

## 中繼資料

 *  版本 **1.1**
 *  最後更新 **14 年前**
 *  啟用安裝數 **100+**
 *  WordPress 版本需求 ** 2.5 或更新版本 **
 *  已測試相容的 WordPress 版本 **3.4.2**
 *  語言
 * [English (US)](https://wordpress.org/plugins/sort-query-posts/)
 * 標籤
 * [post](https://tw.wordpress.org/plugins/tags/post/)[query](https://tw.wordpress.org/plugins/tags/query/)
   [reorder](https://tw.wordpress.org/plugins/tags/reorder/)[sort](https://tw.wordpress.org/plugins/tags/sort/)
 *  [進階檢視](https://tw.wordpress.org/plugins/sort-query-posts/advanced/)

## 評分

 5 星，滿分為 5 星

 *  [  3 個 5 星使用者評論     ](https://wordpress.org/support/plugin/sort-query-posts/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/sort-query-posts/reviews/?filter=4)
 *  [  0 個 3 星使用者評論     ](https://wordpress.org/support/plugin/sort-query-posts/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/sort-query-posts/reviews/?filter=2)
 *  [  0 個 1 星使用者評論     ](https://wordpress.org/support/plugin/sort-query-posts/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/sort-query-posts/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/sort-query-posts/reviews/)

## 參與者

 *   [ Tubal ](https://profiles.wordpress.org/tubal/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/sort-query-posts/)