wordpress - WP All Import 插件 - 设置永久链接页面
问题描述
我正在处理一个庞大的页面(超过 70,000 页)集成项目,感谢 WP All Import 我可以使用我的 csv 文件中的数据创建页面,这里的问题是我想根据我的 CSV 文件的某些值设置永久链接()。
例如我想创建 URL:
website.com/destinations/UK/london
website.com/destinations/UK/london/agency1
website.com/destinations/UK/london/agency2
website.com/destinations/FR/paris
website.com/destinations/FR/paris/agency1
website.com/destinations/FR/paris/agency2
国家(英国、法国……)等于我的 CSV 文件中的一列 城市(伦敦、巴黎……)等于我的 CSV 文件中的一列 代理(agency1、agency2……)等于我的 CSV 中的一列文件
有人可以帮助我吗?
谢谢 :)
解决方案
我不知道您是否可以更新整个永久链接,但您可能可以使用与此类似的内容(未经测试)更新 post slug(表中的post_name
列wp_posts
):
function my_saved_post( $post_id, $xml_node, $is_update ) {
// Retrieve the import ID.
$import_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['import_id'] ) ? $_GET['import_id'] : 'new' ) );
// Only run for import 8. TODO: Change this to your import ID!
if ( $import_id == '8' ) {
// Convert SimpleXml object to array for easier use.
$record = json_decode( json_encode( ( array ) $xml_node ), 1 );
// verify post is not a revision
if ( ! wp_is_post_revision( $post_id ) ) {
// update the post slug
wp_update_post( array(
'ID' => $post_id,
'post_name' => $record['pays'] . '/' . $record['typedelieu']
));
}
}
}
add_action( 'pmxi_saved_post', 'my_saved_post', 10, 3 );
推荐阅读
- python - 防止在读取/写入 csv 文件时更改 EOL 字符
- django-models - 'Account' 对象没有属性 'products' AND (fields.E301) Field 定义了与模型 'auth.User' 的关系,该模型已被换出。
- rspec - 使用 shell_out 进行 Chef 库测试
- javascript - Mozilla 扩展:变量范围
- python - 为随机化添加更多运动,添加带有矩阵的网格:Tkinter、Python
- ms-access - 从 MS Access 导出多个命名的 PDF - 导出的 PDF 中不显示数据字段
- sharepoint - 从 Sharepoint 页面检索 MS Graph API 访问令牌
- java - 如何在 Android Studio 中随机化我的按钮?
- c - 克服C中缺乏多态性
- python - python: pip 无法安装 matplotlib v.3.1.1