Comment prévenir le double post en vérifiant si le titre du post existent avant d'exécuter “wp_insert_post”?

J'ai un site wordpress qui se connecte à un serveur soap. Le problème est qu'à chaque fois que je lance le script de la "wp_insert_post" utilise le même résultat nouveau. Je voudrais vérifier si existant post_title correspond à la valeur de $titre, alors si elles correspondent, prévenir wp_insert_post d'utiliser la même valeur à nouveau.

Voici le code:

try {
    $client = new SoapClient($wsdl, array('login' => $username, 'password' => $password));
    } catch(Exception $e) {
      die('Couldn\'t establish connection to weblink service.');
    }
$publications = $client->GetPublicationSummaries();
foreach ($publications->GetPublicationSummariesResult->PublicationSummaries->PublicationSummary as $publication_summary) {

    //get the complete publication from the webservice
    $publication = $client->getPublication(array('PublicationId' => $publication_summary->ID))->GetPublicationResult->Publication;

    //get all properties and put them in an array
    $properties = array();
    foreach ($publication->Property as $attribute => $value) {
        $properties[$attribute] = $value;
    }

    //Assemble basic title from properties
    $title = $properties['Address']->Street . ' ' . $properties['Address']->HouseNumber . $properties['Address']->HouseNumberExtension . ', ' . $properties['Address']->City->_;
}

$my_post = array(
    'post_title'=>$title,
    'post_content'=>'my contents',
    'post_status'=>'draft',
    'post_type'=>'skarabeepublication',
    'post_author'=>1,
);
wp_insert_post($my_post);

Merci pour toute aide.

  • vous devriez essayer ce code. besoin( dirname(FICHIER) . '/wp-load.php' ); global $wpdb; echo $count = $wpdb->get_var("select COUNT(*) from $wpdb->les postes où post_title comme '$titre' ");