Forums

Find post ID with custom value (3 posts)

  1. phillydan
    Member
    Posted 5 years ago #

    I'm trying to make a WP site similar to Digg. Everything is working great, except that I want to make sure people do not submit duplicate articles.

    What I need is a function that searches WordPress for any posts with a specific custom field value (like "www.wordpress.org" for the "storyLink" field), and just get back the ID# of that post. That way, I'll know if that URL has been posted or not, and take appropriate action.

    I do *not* want to display the post itself. I just need the ID#, or a false if the URL hasn't been entered yet. (I'm aware of szub's plugin: http://guff.szub.net/2006/04/21/search-custom-fields/ but that just gives a search result)

    Thank you so much for helping me out!

  2. Austin Matzko
    Member
    Posted 5 years ago #

    function find_post_IDs_with_this_text_in_storyLink($text) {
    global $wpdb;
    return $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'storyLink' AND meta_value LIKE '%$text%'");
    }

    $array_of_post_ids_mentioning_the_word_car = (array) find_post_IDs_with_this_text_in_storyLink('car');

  3. phillydan
    Member
    Posted 5 years ago #

    filosofo, you're my hero! thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic