WP All Import插件-设置永久链接页面

时间:2020-10-28 14:53:01

标签: wordpress wpallimport

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

Capture WP All Import

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

有人可以帮助我吗?

谢谢:)

1 个答案:

答案 0 :(得分:0)

我不知道您是否可以更新整个永久链接,但是您可以使用类似以下内容(未经测试)来更新后段(post_name表中的wp_posts列):< / p>

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 );

受到documentationthis SE answer的启发。