title: Get last ID of posts with same title
body: <p>I need to get the ID of the posts that have the same title.
  I am using the <code>posts_exists</code> function, modifying it in functions.php because I need this operation in the front end, but this function returns the ID of the oldest post. I need the ID of the most recent post.
  I tried changing this line
  <code>$query = &quot;SELECT ID FROM $wpdb-&gt;posts WHERE 1=1&quot;;</code>
  with this
  <code>$query = &quot;SELECT ID FROM $wpdb-&gt;posts ORDER BY $wpdb-&gt;posts.ID DESC WHERE 1=1&quot;;</code>
  But it doesn't work</p>
  <p>How can I change this function to have the most recent post ID?</p>
  <pre><code>function post_exists_fe( $title,  $type = '' ) {
      global $wpdb;
   
      $post_title   = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
      $post_type    = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
   
      $query = &quot;SELECT ID FROM $wpdb-&gt;posts WHERE 1=1&quot;;
      $args  = array();
    
      if ( ! empty( $title ) ) {
          $query .= ' AND post_title = %s';
          $args[] = $post_title;
          $dajenamo = end($args);
      }
  
      if ( ! empty( $type ) ) {
          $query .= ' AND post_type = %s';
          $args[] = $post_type;
      }
   
      if ( ! empty( $args ) ) {
       return (int) $wpdb-&gt;get_var( $wpdb-&gt;prepare( $query, $args ) );
      
      }
   
      return 0;
  }
  
  </code></pre>