Вопросительный знак и знак равенства не отображаются в WordPress post_name

Поэтому я хочу добавить следующее ?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.

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

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector