最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Preg Match All doesn't Allow echo first character for Wordpress Taxonomy Tags

programmeradmin2浏览0评论

I have been working on a code, that finds particular words from my content and converts them to wordpress Taxonomy Tags. I want to prefix them with a '#' symbol... But somehow it doesn't work

This is the code:

 preg_match_all('/ #([A-Za-z\/\.]*) /', $content, $matches, PREG_PATTERN_ORDER); 
if(isset($matches[1])){ 
foreach($matches[1] as $matchKey){ 
    $HashTag= $matchKey;
wp_set_post_tags( $ID, '#'.$HashTag, true); 
} 

The issue is in the second last line of the code...

wp_set_post_tags( $ID, '#'.$HashTag, true); 

I put a # symbol behind my text when setting post tags... But when the code executes the # is ommited and only $HashTag is echoed....

I tried to see if the issue is with something else so i tried using other words and alphabets other than '#'

wp_set_post_tags( $ID, 'ABC'.$HashTag, true); 

It worked perfectly and had ABC behind each of my tags. I tried to do it with single alphabet and yet again it worked.

wp_set_post_tags( $ID, 'Z'.$HashTag, true); 

But still I fail to do the trick with '#' symbol, so please help me out...

Thanks in Advance...

发布评论

评论列表(0)

  1. 暂无评论