Add first url to custom field on publish_post
-
I post a lot using Press This and I allow other users to post. Lately I noticed some duplicates and I m trying to find a way to stop this. I am trying to get the first link from the post, add it to a custom field which will be checked on each publish_post and if it exists add the user’s name in another custom field.
I did one test and the url was added to the “link” custom field and that s it. It stopped working. I m not sure what I m doing wrong.
add_action( 'publish_post', 'check_post' ); function check_post( $post_id ) { $user_info = get_userdata(1); function get_first_link() { global $post, $posts; preg_match_all('/href\s*=\s*[\"\']([^\"\']+)/', $post->post_content, $links); return $links[1][0]; } $first_link = get_first_link(); add_post_meta($post_id, 'link', $first_link, true); add_post_meta($post_id, 'users', $user_info->user_login, true); }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Add first url to custom field on publish_post’ is closed to new replies.