Created
March 3, 2020 23:32
-
-
Save lgedeon/6929c285002a05677fbd8de01392f494 to your computer and use it in GitHub Desktop.
Search post_content for keywords across entire database. Ugly but fast.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( | |
'after_setup_theme', | |
function() { | |
global $wpdb; | |
foreach ( [ 'twitter.com', 'facebook.com', 'instagram.com', 'youtube.com', 'soundcloud.com' ] as $s ) { | |
echo "\n$s"; | |
$results = $wpdb->get_results( "SELECT * FROM `wp_3_posts` WHERE `post_content` LIKE '%$s%' ORDER BY `ID` DESC LIMIT 200;" ); | |
//$results = $wpdb->get_results( "SELECT * FROM wp_3_posts LIMIT 10" ); | |
foreach ( $results as $result ) { | |
preg_match_all( "/.*$s.*/i", $result->post_content, $matches ); | |
foreach ( $matches as $match ) { | |
echo "\n $result->post_date $result->ID \n"; | |
var_export( $match[0] ); | |
} | |
} | |
} | |
die(); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment