WordPress开发函数add_permastruct(),添加永久链接结构。

用法:

add_permastruct( string $name, string $struct, array $args = array() )

描述

参见also

WP_Rewrite: add_permastruct ()

参数:

$name

(string) (必需) 永久链接结构的名称。

$struct

(string) (必需) 永久链接结构。

$args

(array) (可选) 从permalink结构构建规则的参数,请参阅WP_Rewrite::add_permastruct()了解详细信息。

默认值: array()

来源:

文件: wp-includes/rewrite.php

function add_permastruct( $name, $struct, $args = array() ) {

global $wp_rewrite;

// Back-compat for the old parameters: $with_front and $ep_mask.

if ( ! is_array( $args ) ) {

$args = array( 'with_front' => $args );

}

if ( func_num_args() == 4 ) {

$args['ep_mask'] = func_get_arg( 3 );

}

$wp_rewrite->add_permastruct( $name, $struct, $args );

}

更新日志:
WordPress开发函数add_permastruct() (https://www.wpzt.net/) WordPress开发教程 第1张
用户贡献的笔记

(由Marcio Zebedeu贡献- 2年前)

您可以更改规则来重写您的发布类型以及更改您的结构。假设你的永久链接结构是这样的:

/locations/%k7_locations%

你可以切换到

/test/%message%

global $wp_rewrite;

$args = array(

'with_front' => true,

'ep_mask' => 3,

'paged' => 1,

'feed' => 1,

'forcomments' => 0,

'walk_dirs' => 1,

'endpoints' => 1

);

add_permastruct( 'locations', 'test/%message/', $args);

输出:

Array

(

[with_front] => 1

[ep_mask] => 3

[paged] => 1

[feed] => 1

[forcomments] => 0

[walk_dirs] => 1

[endpoints] => 1

[struct] => /test/%message/%

)