Forums

[resolved] Check if post title already exists (4 posts)

  1. sastronot
    Member
    Posted 2 years ago #

    I post content via wp_insert_post() but i need to check if the title already posted.
    Also what is the function to convert title "Hannah Teter Sports Illustrated" to "hannah-teter-sports-illustrated" ?

    Please help

  2. alchymyth
    The Sweeper
    Posted 2 years ago #

    // check if title $my_post_name already exists in wpdb
    global $wpdb;
    if($wpdb->get_row("SELECT post_title FROM wp_posts WHERE post_title = '" . $my_post_name . "'", 'ARRAY_A')) {
    echo $my_post_name.' already exists'; }

    google came up with this article about post slugs:
    http://www.bernzilla.com/item.php?id=1007

    http://codex.wordpress.org/Function_Reference/sanitize_title_with_dashes

    (wp2.9: around line 770 in wp-includes/formatting.php)

  3. sastronot
    Member
    Posted 2 years ago #

    Thanks alchymyth. It works...

  4. archiparmentier
    Member
    Posted 2 years ago #

    it doesn't work in wp2.9.2
    why ?

Topic Closed

This topic has been closed to new replies.

About this Topic