首页 > 解决方案 > WP All Import 插件 - 设置永久链接页面

问题描述

我正在处理一个庞大的页面(超过 70,000 页)集成项目,感谢 WP All Import 我可以使用我的 csv 文件中的数据创建页面,这里的问题是我想根据我的 CSV 文件的某些值设置永久链接()。

捕获 WP 全部导入

例如我想创建 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 中的一列文件

有人可以帮助我吗?

谢谢 :)

标签: wordpresswpallimport

解决方案


我不知道您是否可以更新整个永久链接,但您可能可以使用与此类似的内容(未经测试)更新 post slug(表中的post_namewp_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 );

文档这个 SE 答案的启发。


推荐阅读