A
A
amagon2018-05-10 19:31:20
HTML
amagon, 2018-05-10 19:31:20

Why can the metabox truncate the "?

Good afternoon. Created an additional field following an example from the network

function my_meta_box() {  
    add_meta_box(  
        'my_meta_box', // Идентификатор(id)
        'My Meta Box', // Заголовок области с мета-полями(title)
        'show_my_metabox', // Вызов(callback)
        'post', // Где будет отображаться наше поле, в нашем случае в Записях
        'normal',
        'high');
}  
add_action('add_meta_boxes', 'my_meta_box'); // Запускаем функцию
 
$meta_fields = array(  
    array(  
        'label' => 'текстовое поле',  
        'desc'  => 'описание для поля.',  
        'id'    => 'mytextinput', // даем идентификатор.
        'type'  => 'text'  // Указываем тип поля.


  // Начинаем выводить таблицу с полями через цикл
    echo '<table class="form-table">';  
    foreach ($meta_fields as $field) {  
        // Получаем значение если оно есть для этого поля 
        $meta = get_post_meta($post->ID, $field['id'], true);  
        // Начинаем выводить таблицу
        echo '<tr> 
                <th><label for="'.$field['id'].'">'.$field['label'].'</label></th> 
                <td>';  
                switch($field['type']) {  
                    case 'text':  
    echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="70" />
        <br /><span class="description">'.$field['desc'].'</span>';  
break;

The field appeared in the admin panel and works, the data from it is displayed in the right part of the article, but if I put text into it with a symbol, "for example , <a href="https://www.sitethen the part after "is simply cut off. Why is this happening and is there a recipe for how to fix it? By the way, while introducing this question here, the text was also cut off

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Mavlikhanov, 2018-05-11
@amagon

By try to wrap :
It was
It became

$meta = get_post_meta($post->ID, $field['id'], true);  
 $meta = esc_attr($meta);

https://wp-kama.ru/function/esc_attr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question