Привет, у меня проблемы с WordPress. Получите изображения, обычно я использую эту функцию для установки изображений WordPress.
function generate_featured_images($post_id, $image, $title){
// only need these if performing outside of admin environment
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// magic sideload image returns an HTML image, not an ID
$media = media_sideload_image($image, $post_id);
//$filename = basename($image);
$info = pathinfo($image);
$filename = sanitize_title($title).'.'.$info['extension'];
// therefore we must find it so we can set it as featured ID
if(!empty($media) && !is_wp_error($media)){
$args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'any',
'post_parent' => $post_id
);
// reference new image to set as featured
$attachments = get_posts($args);
if(isset($attachments) && is_array($attachments)){
foreach($attachments as $attachment){
// grab source of full size images (so no 300x150 nonsense in path)
$image = wp_get_attachment_image_src($attachment->ID, 'full');
// determine if in the $media image we created, the string of the URL exists
if(strpos($media, $image[0]) !== false){
// if so, we found our image. set it as thumbnail
set_post_thumbnail($post_id, $attachment->ID);
//resize_image_high($post_id);
// only want one image
break;
}
}
}
}
return '';
}
И чтобы я вызывал эту функцию, используя:
generate_featured_images( 123, "http://website.com/img/img1.jpg", "img name");
Этоработает нормально, используя эту функцию.
Но проблема возникла из-за того, что URL-адрес не показывает расширение, например "https://cf.shopee.co.id/file/09a73246d7fe87eb490e9c8f99b876e1" Я пытаюсь, это не работает, и я действительно пытаюсь найти несколько дней, ноне нашел решения, помогите пожалуйста.