【问题标题】:WP All Import plugin - Set permalink pageWP All Import 插件 - 设置永久链接页面
【发布时间】:2020-10-28 14:53:01
【问题描述】:

我正在处理一个大型页面(超过 70,000 个页面)集成项目,感谢 WP All Import 我可以使用我的 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 文件中的一列 Agency (agency1, Agency2....) 等于我的 CSV 文件中的一列

有人可以帮助我吗?

谢谢:)

【问题讨论】:

标签: wordpress wpallimport


【解决方案1】:

我不知道您是否可以更新整个永久链接,但您可能可以使用类似于此的内容(未经测试)更新 post slug(wp_posts 表中的 post_name 列):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    相关资源
    最近更新 更多