Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
}
share|improve this question
    
Define "stopped working". What do you expect to happen? What Actually happens? –  Rarst Oct 9 '12 at 22:26
    
the "link" custom field is empty. I want it to contain the first url from the post content. –  ciprian Oct 10 '12 at 3:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.