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
- ERROR: Your feed is invalid (after update WP4.7) in custom types
- Editing the default page to show all posts, rather than most recent ones
- Unable to restore from backup – how to obtain old blog posts?
- MySql query to get posts with all meta and terms
- Automatically add date to the auto generation of post slug
- Permission issue with custom post type – not added to menu – by plugin
- Duplicate Custom Post Type and Taxonomy Slug
- How could I change my Permalink from blog to custom structure? [closed]
- Categories list into registration form
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Take a received feedback item, turn it into a post
- Getting value from get_post_custom
- WP Admin register taxonomy and post type performance
- Static posts page with home.php
- Calling Different Custom Post Timestamps in a table
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Admin – create custom post status and display above table
- Creating a post from data returned from HTML form
- custom post template file not shown, instead all the time 404.php
- Set Default Category to Username
- Query Posts With Over 1000 Views
- How to allow visitors to filter posts by multiple taxonomies
- Cannot retrieve a custom RSS field from posts
- show custom post type category dropdown sorting result on same page
- Custom Post Type Rewrite To Include Parent Page(s)
- Thumbnail & Category link aside post
- Hooking into the post editing screen for an existing page only
- Query Posts by Custom Field
- Redirect to another page using contact form 7? [closed]
- How to include my own css in post
- Custom post types related to same custom post type?
- Dynamically switch template on click
- post category in wp_insert_post
- How to rate a post from Admin Side / Manually?
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- When creating a post how do you select the format?
- Is it possible to customize the post according to post format in single.php?
- How to I retrieve the ID from the Posts page?
- a little direction on custom post type
- disable Tab post on nav-menus page (Admin)
- Format latest/newest post differently
- Get post ID from a link
- Custom taxonomy archive page problem
- Tell WP to use a specific template file in posts
- Create a list of posts with topic headdings
- Add field to user meta table in database when link is clicked
- Hide custom metabox value from custom fields
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- relating business and products with custom taxonomy?
- Best Way to Add UnEditable HTML to Posts
- Get post meta retrieving wrong value
- How safe is it to delete old posts edits to save database space?
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- Using setup_postdata() with multi-dimensional array
- Is codex right on deleting post?
- Check if a custom post type has already been created
- WordPress Query Posts From Category Post on Static Page
- Create a custom posts page
- 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 get different Related Posts
- How to add convenient buttons for new custom post statuses
- How to allow multiple thumbnail upload for Posts?
- add external project to web site wordpress on production
- Output Post with ACF Fields into other Post
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- Saving Post Data in Another Database
- Show custom post with custom categories with specific slug
- register_post_type permalink
- Display the 2nd category name of a custom post type without error if its null?
- Auto delete posts based on content text
- How to call posts under a specific category on static front page?
- Querying another post category to match current post and display in loop
- Custom home page with full post for first one only
- Custom Post Limit for homepage only without plugin?
- Add two custom fields as a default to the “new post” page.
- After ajax image is outside the “ tag
- Display value of custom field at the beginning of a post
- Edit custom fields in posts list
- Add multiple meta keys to a post at once
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- datepicker value in mysql
- WP_Query custom field pass the post id
- Inserting an example of the last 3 post on to the homepage
- Adding post date will not insert new post
- wp_insert_post not working fine
- Insert data from custom created PHP page into wp_postmeta table
- Static pages not working