Вопросительный знак и знак равенства не отображаются в WordPress post_name - PullRequest
0 голосов
/ 06 ноября 2018

Итак, я хочу добавить следующее ?matchPostId=$matchId в post_name на wordpress, используя wp_insert_post();

Я пытался использовать urlencode(); and urldecode();, но все еще не могу заставить его работать, везде проверено, но кажется, что вопросительный знак и знак равенства всегда вырезаются в URL моего поста. Кто-нибудь знает, почему это происходит? Вот мой код:

$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 голосов
/ 06 ноября 2018

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

...