title: Wordpress - Check if post exists,if yes update fields
body: <p>I use a frontend form to post, and what i want is to check if a post exists by title.If yes and metafield value is bigger than the old one,just replace the value.
  Anyone that has implemented something like that in the past?</p>
  
  <pre><code> &lt;?php 
   session_start();
   $user_email = $_SESSION['user_email']; 
   $user_name = $_SESSION['user_name'];
   $user_img_url = 'https://graph.facebook.com/'.$user_name.'/picture?width=200&amp;height=200';
  
              global $wpdb;
              global $post;
              $title = $user_name; // get the inputted title
              $content = $_POST['content']; // get the inputted content
              $categorie = $_POST['cat'];  // get the category selected by user
              $zombies = $_POST['zombies'];
              $kliks = $_POST['klik'];
              $timess = $_POST['times'];
              $name = $_POST['namn'];
  
  
                if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { // if form has been submitted
  
  
                      $my_post = array(
                       'post_title' =&gt; $title,
                       'post_content' =&gt; $content,
                       'post_status' =&gt; 'publish',
                       'post_author' =&gt; 2,
                       'post_category' =&gt; array(2),
                        );
  
                  $my_post = wp_insert_post($my_post);
                  add_post_meta($my_post, 'Zombies', $zombies);
                  add_post_meta($my_post, 'klik', $kliks);
                  add_post_meta($my_post, 'times', $timess);
                  add_post_meta($my_post, 'namn', $name);
                  add_post_meta($my_post, 'profile_photo', $user_img_url);
                  wp_redirect( home_url() );
  
  
                    # if $verifica is not empty, then we don't insert the post and we display a message
  
                } 
          ?&gt;
  </code></pre>