To save the link in the post meta you can use 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){
//add new post
}
is not working, change it to
if (empty($posts)){
//add new post
}
Related Posts:
- Add a checkbox to post screen that adds a class to the title
- Add custom fields to post programmatically
- Add a custom meta box in the post options that loads some html code in the header
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Customize rel=canonical tag for single blog post
- Edit multiple custom post types while saving a new or edited post
- if in category but only with post meta
- Adding an option to post editor to show a site disclaimer or message
- How to only allow post to be deleted if custom field doesn’t exist
- First Custom Post Custom Fields Empty After New Custom Post
- How to Do Custom Fields to Output a Definition List
- Custom Post Types, slug, archive and SEO plugins
- Search Custom Post Type Pages and Custom Fields in 2 Dropdowns?
- Update all posts automatically when using post_meta
- How to disable drafts?
- how to enable different number of revisions for different blogs when using WPMU?
- Custom Post Type Pagination Doesn’t Work in WordPress 3.4
- Post from front-end only by logged in users, form posts as “posted by:
- meta_box or custom_field as a second tinymce post-instance?
- Show One Category on Post
- Create A Metabox For A Custom Field
- WordPress Delete hook with wp_delete_post function?
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- Delete Post From Front-End and attachment permanently
- Custom post type permalinks breaking due to 3.1 bug fix
- Custom fields on a virtual page
- Get a custom field of all posts on current blog page
- Blogroll – Different layout for first post
- How to delete old posts’ edits to save space?
- How can I get a post field value using javascript?
- Archive Page for Custom Post Type is not Working
- Filter Custom Post Type by Category with Ajax
- How can I sort posts by the date and a custom meta field?
- How to prevent duplicate posts with wp_insert_post on single.php?
- Show posts by a custom post author
- Automatically add custom fields value to wordpress post
- Search results posts_orderby and ID
- Making a custom Pagination for multi page blog post
- Unable to restore from backup – how to obtain old blog posts?
- custom post template file not shown, instead all the time 404.php
- Custom Post Type Rewrite To Include Parent Page(s)
- Thumbnail & Category link aside post
- Redirect to another page using contact form 7? [closed]
- When creating a post how do you select the format?
- Custom taxonomy archive page problem
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- How to add convenient buttons for new custom post statuses
- Show custom post with custom categories with specific slug
- Auto delete posts based on content text
- How to call posts under a specific category on static front page?
- Display value of custom field at the beginning of a post
- Add post tags to previously created custom post type
- Why my meta boxes won’t show in front post page?
- add_rewrite_rule and template redirect not working
- Will multiple category descriptions effect my search engine optimization?
- Automate post update for all posts?
- Changing permalink of WordPress
- Hook save_post_cpt not triggered when custom fields are modified
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Pagination Not Working With Custom Post Type Category
- Random post_id at wp_insert_post
- WordPress Pods Custom Post Type – separate Media Upload folder for each custom Post Types
- how to create a category with wp_insert_post and post_category
- Hide or remove custom post status
- Put page on Archived statut after end of publication date
- post and page and custom post type
- My posts page is missing the page title
- Show custom post category for single post
- How can change header text in post careate/edit form
- Add Categories To Custom Post
- How do I set content in my pages so that it remains permanent while blog posts are added below?
- how to redirect page after delete post inside a post page?
- Permalink base only for posts
- Difference between modified post and new post
- Auto populate custom fields by post date
- Creating widget – ask for selecting a post in the admin panel
- ACF Relationship – Get Parent’s Post Object
- issue in wordpress auto delete post and redirect to another 1
- wp query custom orderby not custom field
- Customizing individual images on posts
- Custom Single Post Type not referring to single-post-type.php File
- How to retrieve a post by inputing the url in a custom field and displaying it on an options page
- Custom fields in normal posts
- How to modify specific parts of a post content in WordPress
- Include post on external custom site
- Run Jquery Script after delete post in front end
- “Current” class on a singular page menu item with custom post types?
- get_post_meta property of non object
- How can I allow users (subscribers) to download selected posts into a single PDF? (RESOLVED)
- Choose options via url
- Custom Post Type Pagination 404 Error (if paged>=2) [duplicate]
- Display ONLY Latest Post From Several Categories
- custom post type single page template not working
- Display post structure in function
- How to make a local “scroll to ID” on post?
- Is there any point to using wp_unique_post_slug?
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields