2011-08-05 4 views
2

ma question est sur l'utilisation de wp_insert_post pour insérer le poste avec le type "photo" pas besoin de télécharger l'image maintenant juste je veux insérer l'information de poste dans la base de données J'ai utilisé ce code et travaillecomment insérer une photo en utilisant wp_insert_post

$my_post = array(

    'post_title' => 'My post', 
    'post_content' => 'This is my post.', 
    'post_status' => 'publish', 
    'post_author' => 1, 
     'post_type' => 'photo', 
    'post_category' => array(3) 
); 

la question est que je veux ajouter les informations suivantes 1- le type photo 2- Je veux mettre le poste en tant qu'image en vedette

Répondre

0

Vous devez d'abord télécharger le fichier, alors vous pouvez attacher l'image comme une attac hment à votre poste. C'est le code que j'utilise pour automatiser un blog:

$wp_filetype = wp_check_filetype(basename($filename), null); 
$attachment = array(
'post_mime_type' => $wp_filetype['type'], 
'post_title' => $postTitle, 
'post_content' => '', 
'post_status' => 'inherit' 
); 
$attach_id = wp_insert_attachment($attachment, $filename, $postId); 
// you must first include the image.php file 
// for the function wp_generate_attachment_metadata() to work 
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 
$attach_data = wp_generate_attachment_metadata($attach_id, $filename); 
wp_update_attachment_metadata($attach_id, $attach_data); 
Questions connexes