To save the link in the post meta you can use
like this for example:
if (count($posts) < 0){
update_post_meta
like this for example:
$url = "http://sample.com/entertainment/
default.aspx?tabid=2305&conid=102950";
$my_post = array(
'post_title' => "$title",
'post_content' => "$content",
'post_status' => 'draft',
'post_author' => 1,
'post_category' => array(1),
);
$post_id = wp_insert_post( $my_post );
update_post_meta($post_id,'source_link',$url);
and to prevent the insertion add a simple conditional check:$args = array("meta_key" => "source_link", "meta_value" =>$url);
$posts = get_posts($args);
if (count($posts) < 0){
//add new post
}
if (count($posts) < 0){
}
is not working, change it to **if (empty($posts))**{
//add new post }Maybe if you use something like a wpdb query including the wp_posts and wp_postmeta searching this meta before inserting the post...
$string = 'the_url.html';
$output = $wpdb->get_var($wpdb->prepare("SELECT count(id)
FROM $wpdb->posts wpo, $wpdb->postmeta wpm
WHERE wpo.ID = wpm.post_id
AND wpm.meta_key = 'name_of_ur_meta'
AND wpm.meta_value = '$string'"));
if(empty($output)) {
/* Insert your post */
} else {
/* Update the post or do other thing */
};
No comments:
Post a Comment