最近在给客户英文网站开发产品批量导入功能的时候(woocommerce自带的产品批量导入无法满足用户需求),需要使用数据库插入的方式批量添加产品数据(自在添加文章函数不能满足需求),由于用户需要最终的产品详情页的链接结构为%postname%的形式,那么就需要获取到产品的标题内容,然后将标题内容同时储存到文章别名(post_name)字段中,如果不做任何处理就直接储存,那么储存的别名和标题是一样的,也就是有空格以及其他的html标签,我们仔细观察会发现,WP自动生成的别名都是使用'-'来链接词的,没有空格和其他html字符,所以就找到了sanitize_title()这个函数。
这个函数会将字符串中的html和Php都清除掉,比如:
<?php
$post_name= sanitize_title('LinKine™ Biotin Labeling Kit (Suitable for samples with molecular weight of 6KD to 20KD)');
echo $post_name;
// 输出结果:linkine-biotin-labeling-kit-suitable-for-samples-with-molecular-weight-of-6kd-to-20kd
?>
所以,如果您也有类似需要过滤的内容的时候,可以使用这个函数。希望本篇文章对您能有所帮助!Related: cremation glass sculptures, elizabethan playwrights, shootashellz bodies, 2333 alumni park plaza suite 110 lexington ky 40517, tulare county recent arrests, abby gilmore sophie cachia, avid cider black apple nutrition facts, wendell john bredemus, is dale ellis monta ellis father, awakenings 2023 amsterdam, hunt county property tax search, enhance crossword clue 7 letters, curious george funding wiki, distal femoral osteotomy hardware removal, how to fix residual magnetism in generator,
还没有任何评论,你来说两句吧