我正在使用定制工具以编程方式更新WP 3.01安装中的帖子。有时我确实会通过编程进行更改post_status
使用自定义从草稿到发布SELECT
然而,这似乎破坏了帖子的永久链接。
处于草稿状态时,帖子具有以下链接结构
http://myblog.com/?p=73006
有没有什么“诀窍”可以迫使链接结构发生变化,从而生成适当的永久链接?我正在使用定制工具以编程方式更新WP 3.01安装中的帖子。有时我确实会通过编程进行更改post_status
使用自定义从草稿到发布SELECT
然而,这似乎破坏了帖子的永久链接。
处于草稿状态时,帖子具有以下链接结构
http://myblog.com/?p=73006
有没有什么“诀窍”可以迫使链接结构发生变化,从而生成适当的永久链接?您需要在执行此操作时以编程方式设置slug。SQL触发器可以做到这一点。写的时候别忘了注意重复的slug。
否则,不要使用数据库发布,而是编写一个调用WP API的php脚本。
创建一个.php
在WordPress目录的根目录中创建文件并写入:
<?php
require( \'wp-load.php\' );
$urunler = array(
\'order\' => \'ASC\',
\'post_type\' => \'urun\',
\'post_status\' => null,
\'numberposts\' => -1,
);
$tumurunler = get_posts($urunler);
if ($tumurunler) {
foreach ($tumurunler as $urun) {
$urun->post_name = \'\';
wp_update_post( $urun ); // Update the post into the database
}
}
所以这段代码会加载post_type==\'urun\'
并设置$urun->post_name
字段为空(此字段定义后permalink段塞),然后在调用时WordPress会自动为您填充一个值wp_update_post()
. 如果你想改变post_type\'
到\'post\'
或post_type\'
到\'page\'
只需更改此行:\'post_type\' => \'urun\',