0
votes

I am inserting data in WordPress from my php script, everything is going smooth but i am facing one big problem to set Featured image from external link. I have almost solve this problem by adding image link to wp_postmeta

enter image description here

I have added

_wp_attached_file with external image link  
_thumbnail_id giving it post id of the link

it work fine ... but there a small problem ... image is getting defauld url+external image link

http://****.com/wp-content/uploads/http://i.imgur.com/waiBWaV.jpg

My Question is how can i remove default link http://****.com/wp-content/uploads/ so only external image link display and i get right image.

Thx

2

2 Answers

2
votes

The easiest way is to use regular expression to trim unusefull part of url.

$src = 'http://****.com/wp-content/uploads/http://i.imgur.com/waiBWaV.jpg';
$image =  preg_replace('|.*/(.*?\.[\w]+)|', '\1', $src);
0
votes

to continue with this subject, is there a way to remove the "default url" (wp-content/uploads/) at the source of the code, not with a regex, and only for image with a alt=external ?