generate functionThu, 10 Nov 2022

wordpress loop all posts and extract all links from content

$args = array( 'post_type' => 'post', ); $posts = get_posts($args); foreach($posts as $post) { $content = $post->post_content; $regexp = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/'; preg_match_all($regexp, $content, $matches); $links = $matches[0]; }

Questions about programming?Chat with your personal AI assistant