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

admin2025-04-19  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...

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745072695a283382.html

最新回复(0)