问号和等号未出现在wordpress post_name中

时间:2018-11-06 11:36:50

标签: php wordpress character urlencode

所以我想使用?matchPostId=$matchIdpost_name上的wordpress中添加以下wp_insert_post();

我尝试使用urlencode(); and urldecode();,但仍然无法使它正常工作,在所有地方都进行了检查,但似乎我的帖子的网址中总是划掉问号和等号。有谁知道为什么这样做吗? 这是我的代码:

$questionm = '?';
        $equalsm = '=';
        $tipsPage = $questionm . 'matchPostId' . $equalsm . $matchId;


        $post_idpost = wp_insert_post(
            array(
                'comment_status' => 'closed',
                'ping_status' => 'closed',
                'post_author' => 1,
                'post_name' => $tipsPage,
                'post_title' => $value['test']
                'post_status' => 'publish',
                'post_type' => 'post',
                'post_content' => "test"                

            )           
        );

也尝试过:

$questionm = ('?');
$equalsm = ('=');
urlencode($questionm); 
urlencode($equalsm); 


            $post_idpost = wp_insert_post(
                array(
                    'comment_status' => 'closed',
                    'ping_status' => 'closed',
                    'post_author' => 1,
                    'post_name' => urldecode($questionm) . 'matchPostId' . urldecode($equalsm) . $matchId,

Same problem, the question mark and equals sign is removed from the url.

1 个答案:

答案 0 :(得分:0)

WP在wp_insert_post函数中清除了帖子名。

if ( empty($post_name) ) { 
    if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { 
        $post_name = sanitize_title($post_title); 
    } else { 
        $post_name = ''; 
    } 
} else { 
    // On updates, we need to check to see if it's using the old, fixed sanitization context. 
    $check_name = sanitize_title( $post_name, '', 'old-save' ); 
    if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) { 
        $post_name = $check_name; 
    } else { // new post, or slug has changed. 
        $post_name = sanitize_title($post_name); 
    } 
}

来源:http://hookr.io/functions/wp_insert_post/大约3094行