Skip to content

Instantly share code, notes, and snippets.

@Aziz-Rahman
Created October 12, 2015 06:45
Show Gist options
  • Save Aziz-Rahman/77a77390937504132041 to your computer and use it in GitHub Desktop.
Save Aziz-Rahman/77a77390937504132041 to your computer and use it in GitHub Desktop.
Example table prefix in wp multisite/ not
<?php
if ( is_multisite() ) :
global $wpdb, $table_prefix;
$table_name = $table_prefix . 'postmeta'; // output wp_#_postmeta (multisite) # = id multisite (automatic)
$select_data = $wpdb->get_results( "SELECT meta_value FROM $table_name WHERE meta_value = '$warrior_url_topic'" );
$check_url_exists = $wpdb->num_rows;
foreach ( $select_data as $obj ) {
$wp_data = $obj->meta_value;
}
else :
global $wpdb;
$table_name = $wpdb->base_prefix . 'postmeta'; // output wp_postmeta (not multisite)
$select_data = $wpdb->get_results( "SELECT meta_value FROM $table_name WHERE meta_value = '$warrior_url_topic'" );
$check_url_exists = $wpdb->num_rows;
foreach ( $select_data as $obj ) {
$wp_data = $obj->meta_value;
}
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment