How to correctly escape data

时间:2017-01-30 作者:Pravayest Pravayest

我想获取最近的帖子,我使用wp\\u get\\u recent\\u posts:

<?php $args = array(
    \'numberposts\' => \'3\',
    \'post_status\' => \'publish\',
    \'orderby\' => \'rand\'
);

$recent_posts = wp_get_recent_posts($args);?>
然后我想在页面上显示帖子信息:

<?php foreach( $recent_posts as $recent ){?>
    <li>
        <?php echo the_category(\'/\',\'\',$recent["ID"]); ?>
        <?php echo get_permalink($recent["ID"]) ?>
        <?php echo $recent["post_title"]?></h2>
        <?php echo get_the_date(\'F j, Y\',$recent["ID"])?>
        <?php echo  get_the_post_thumbnail($recent["ID"],\'bereza-carousel\');?>
    </li>
    <?php
}?>
但必须正确转义所有动态数据。那么,如何正确地转义数据呢?

1 个回复
SO网友:decoder88

您可能想查看有关此主题的WordPress官方文档,在您的案例中,重点是转义输出https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data