How to get a list of all table prefixes within the same database?

Home Forums WordPress Development How to get a list of all table prefixes within the same database?

Tagged: ,

Viewing 0 reply threads
  • Author
    Posts
    • #8945
      Rafasashi
      Keymaster

      This snippet lists all table prefixes from other WordPress installations within the same database:

      
      function get_prefix_options(){
      	
      	global $wpdb;
      	
      	$table_names = $wpdb->get_results("SHOW TABLES LIKE '%_postmeta'", ARRAY_N);
      
      	$prefixes = array();
      
      	foreach ($table_names as $table) {
      		
      		$prefix = str_replace('_postmeta', '', $table[0]);
      
      		if ( !in_array($prefix,$prefixes) ) {
      			
      			$prefixes[] = '_' . $prefix;
      		}
      	}
      	
      	return $prefixes;
      }
      
Viewing 0 reply threads
  • You must be logged in to reply to this topic.