定制 sectsect/wp-tag-order 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sectsect/wp-tag-order

Composer 安装命令:

composer require sectsect/wp-tag-order

包简介

Sort the tags manually in individual posts on wordpress.

README 文档

README

Plugin Check PHP Unit Tests PHPStan PHP Coding Standards TypeScript Code Quality CodeQL

Order tags independently in each posts (not site-globally) on WordPress with simple Drag-and-Drop ↕︎ sortable feature.

Important

This plugin is NOT compatible with Gutenberg on WordPress 5.x. Consider using Classic Editor Plugin.

Important

Mutation events will no longer be supported in Google Chrome and Edge in July 2024 (Google Chrome on July 23, 2024, and Microsoft Edge the week of July 25, 2024). As a result, WP Tag Order versions 3.6.0 or less will not work with Chrome v127 and later, which will be released on July 23, 2024.
You have to update to v3.7.0 or later.
See Chrome for Developers Blog for more details.
If you still need PHP7 support, see Troubleshooting below.

Features

  • 🏷️ Custom tag ordering for posts
  • 🔍 Works with default WordPress tag and custom taxonomy systems
  • 🔢 Drag-and-Drop interface for easy tag reordering
  • 📊 Supports multiple post types and taxonomies
  • 🔧 NEW: Programmatic Tag Order Management
  • 🌐 NEW: REST API Support
    • Retrieve ordered tags via GET endpoint
    • Update tag order programmatically
    • Supports authentication and permissions
  • 🚀 Lightweight and performance-optimized

Get Started

  1. Clone this Repo into your wp-content/plugins directory.
cd /path-to-your/wp-content/plugins
git clone git@github.com:sectsect/wp-tag-order.git
  1. Activate the plugin through the Plugins menu in WordPress.
  2. Go to Settings -> WP Tag Order page to select which taxonomies to enable ordering for.

Notes

  • When creating a new post, you need to save it once to enable tag ordering.
  • To apply ordering to existing posts, "Add and Remove" any tag once.
  • To bulk-update multiple posts at once, go to Settings -> WP Tag Order page and click 'Apply' under the Advanced Settings.
  • Tested on WordPress v6.3.1.

Requirements

  • WordPress 5.6+
  • PHP 8.0+

APIs

Function Description
get_the_tags_ordered() Based on get_the_tags() - Codex
get_the_terms_ordered() Based on get_the_terms() - Codex
get_the_tag_list_ordered() Based on get_the_tag_list() - Codex
get_the_term_list_ordered() Based on get_the_term_list() - Codex
the_tags_ordered() Based on the_tags() - Codex
the_terms_ordered() Based on the_terms() - Codex

Usage Example

get_the_tags_ordered()

<?php
$terms = get_the_tags_ordered();
if ( $terms && ! is_wp_error( $terms ) ) :
?>
<ul>
    <?php foreach ( $terms as $term ) : ?>
        <li>
            <a href="<?php echo get_term_link( $term->slug, 'post_tag' ); ?>">
                <?php echo $term->name; ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

get_the_terms_ordered()

<?php
$terms = get_the_terms_ordered( $post->ID, 'post_tag' );
if ( $terms && ! is_wp_error( $terms ) ) :
?>
<ul>
    <?php foreach ( $terms as $term ) : ?>
        <li>
            <a href="<?php echo get_term_link( $term->slug, 'post_tag' ); ?>">
                <?php echo $term->name; ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

get_the_tag_list_ordered()

<?php echo get_the_tag_list_ordered(); ?>

get_the_term_list_ordered()

<?php echo get_the_term_list_ordered( $post->ID, 'post_tag' ); ?>

the_tags_ordered()

<?php the_tags_ordered(); ?>

the_terms_ordered()

<?php the_terms_ordered( $post->ID, 'post_tag' ); ?>

Programmatic Tag Order Management

The plugin provides a Tag_Updater class for developers to programmatically manage tag order:

$tag_updater = new \WP_Tag_Order\Tag_Updater();

try {
    // Update tag order using an array or comma-separated string
    $result = $tag_updater->update_tag_order(
        get_the_ID(),   // Post ID
        'post_tag',     // Taxonomy that enabled in plugin settings
        [1, 2, 3]       // Tag IDs in desired order
    );
} catch ( \InvalidArgumentException $e ) {
    // Error handling
    error_log( $e->getMessage() );
}

This class allows flexible tag order updates directly from your theme or custom plugin code, supporting both array and string inputs with robust validation.

Return Value

update_tag_order() returns: int|bool

  • int: Meta ID if the tag order meta key didn't previously exist
  • true: Successful update of existing meta
  • false: Update failed or the new tag order is identical to the existing order

REST API

The WP Tag Order plugin provides two REST API endpoints for managing tag order:

Get Tag Order

  • Endpoint: /wp-json/wp-tag-order/v1/tags/order/{post_id}
  • Method: GET
  • Parameters:
    • post_id (required): The ID of the post
    • taxonomy (optional): Taxonomy name (defaults to 'post_tag')
  • Permissions: Publicly accessible
  • Response: Array of ordered tags with full term details

Example Request

GET /wp-json/wp-tag-order/v1/tags/order/123
w/ cURL
curl --location 'https://your-wordpress-site.com/wp-json/wp-tag-order/v1/tags/order/123'

Update Tag Order

  • Endpoint: /wp-json/wp-tag-order/v1/tags/order/{post_id}
  • Method: PUT or PATCH
  • Parameters:
    • post_id (required): The ID of the post
    • taxonomy (required): Taxonomy name
    • tags (required): Comma-separated list of tag IDs in desired order
  • Permissions: Requires user authentication and post edit capabilities
  • Response: Success status and message

Example Request

PUT /wp-json/wp-tag-order/v1/tags/order/123
{
  "taxonomy": "post_tag",
  "tags": "5,3,1,4,2"
}
w/ cURL
curl --location --request PUT 'https://your-wordpress-site.com/wp-json/wp-tag-order/v1/tags/order/123' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_JWT_TOKEN' \
--data '{
  "taxonomy": "post_tag",
  "tags": "5,3,1,4,2"
}'

Example Response

{
  "success": true,
  "code": "tags_order_updated",
  "message": "Tag order updated successfully.",
  "data": {
    "status": 200,
    "post_id": 123,
    "taxonomy": "post_tag",
    "tags": [
      5,
      3,
      1,
      4,
      2
    ]
  }
}

Get Enabled Taxonomies

  • Endpoint: /wp-json/wp-tag-order/v1/taxonomies/enabled
  • Method: GET
  • Parameters: None
  • Permissions: Publicly accessible
  • Response: Array of enabled taxonomies with metadata

Example Request

GET /wp-json/wp-tag-order/v1/taxonomies/enabled
w/ cURL
curl --location 'https://your-wordpress-site.com/wp-json/wp-tag-order/v1/taxonomies/enabled'

Example Response

{
  "enabled_taxonomies": [
    "post_tag",
    "product_tag"
  ],
  "available_taxonomies": [
    "post_tag",
    "product_tag",
    "event_tag"
  ],
  "meta": {
    "enabled_count": 2,
    "available_count": 3,
    "timestamp": "2025-09-23T04:58:23+00:00"
  }
}

Authentication

  • GET requests are publicly accessible
  • PUT/PATCH requests require:
    • User to be logged in
    • User to have edit permissions for the specific post
    • Post must be of an allowed type (default: 'post' or 'page')

For Developers

  • The ordered tag data is serialized and stored in the wp_postmeta table under keys like wp-tag-order-{taxonomy}.

    meta_id post_id meta_key meta_value
    19 7 wp-tag-order-post_tag s:91:"a:7:{i:0;s:1:"7";i:1;s:1:"5";i:2;s:2:"10";i:3;s:1:"4";i:4;s:1:"6";i:5;s:1:"8";i:6;s:1:"9";}";
  • This Plugin does not hosting on the wordpress.org repo in order to prevent a flood of support requests from wide audience. Your feedback is welcome.

Troubleshooting

Still need support for PHP 7.

I have a branch php7 to support PHP 7 and End-of-Life for JaveScript Mutation events.
The branch will not be maintained anymore, so I recommend you migrate to PHP 8.

Change log

See CHANGELOG file.

License

See LICENSE file.

✌️

A little project by @sectsect

sectsect/wp-tag-order 适用场景与选型建议

sectsect/wp-tag-order 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 400 次下载、GitHub Stars 达 21, 最近一次更新时间为 2017 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「wordpress」 「order」 「github」 「tags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sectsect/wp-tag-order 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sectsect/wp-tag-order 我们能提供哪些服务?
定制开发 / 二次开发

基于 sectsect/wp-tag-order 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 400
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2017-01-30