最新公告
  • 欢迎您光临知事网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入我们
  • WordPress函数wp_check_for_changed_slugs()用法 判断文章别名是否已修改

    描述:

    判断文章/页面的别名是否已经修改

    用法:

    <?php wp_check_for_changed_slugs( $post_id ); ?>

    参数:

    $post_id
    
    (integer) (必填) 文章ID.
    
    默认值: None

    源文件:

    /**
    * Check for changed slugs for published post objects and save the old slug.
    *
    * The function is used when a post object of any type is updated,
    * by comparing the current and previous post objects.
    *
    * If the slug was changed and not already part of the old slugs then it will be
    * added to the post meta field ('_wp_old_slug') for storing old slugs for that
    * post.
    *
    * The most logically usage of this function is redirecting changed post objects, so
    * that those that linked to an changed post will be redirected to the new post.
    *
    * @since 2.1.0
    *
    * @param int $post_id Post ID.
    * @param WP_Post $post The Post Object
    * @param WP_Post $post_before The Previous Post Object
    */
    function wp_check_for_changed_slugs( $post_id, $post, $post_before ) {
    // Don't bother if it hasnt changed.
    if ( $post->post_name == $post_before->post_name )
    return;
    
    // We're only concerned with published, non-hierarchical objects.
    if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) )
    return;
    
    $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
    
    // If we haven't added this old slug before, add it now.
    if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) )
    add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);
    
    // If the new slug was used previously, delete it from the list.
    if ( in_array($post->post_name, $old_slugs) )
    delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
    }
    找互联网优质资源,上知事网!
    知事网 » WordPress函数wp_check_for_changed_slugs()用法 判断文章别名是否已修改

    常见问题FAQ

    网盘提取密码在哪里?
    在网站右侧有个“文件密码”,点击复制即可!
    网站的积分如何获得?
    注册登录后,每天签到可获得2个积分,每天可签到一次!

    发表评论

    • 1231会员总数(位)
    • 665资源总数(个)
    • 21本周发布(个)
    • 0 今日发布(个)
    • 3457稳定运行(天)

    提供最优质的资源集合

    Mac软件 Dedecms源码
    升级SVIP尊享更多特权立即升级