0

what's different between wpdb->prefix and table_prefix i want to install db table of my plugin for example

$wps_user_visits_table_prefix = $wpdb->prefix.'wps_user_visits';

is equal to

$wps_user_visits_table_prefix = $table_prefix.'wps_user_visits';

or diffrent ?

  • What is table_prefix? Where is it coming from? That does not look like normal standard WordPress – Tom J Nowell Jun 14 '18 at 14:08
0

The difference is pretty simple.

$wpdb->prefix is getting the prefix field from global $wpdb object.

$table_prefix can be anything. Most probably it's some local variable that contains the same value, but you can assign anything to that variable.

So using $wpdb->prefix is a better idea - it's nicer, cleaner and more obvious.

  • as you said i don't need $table_prefix and instead of always i can use $wpdb->prefix; yes ? or no ? – tabesh Jun 15 '18 at 13:20
  • Yes, $table_prefix is just some local variable - it doesn't come "from" WordPress so it's impossible to say what it is exactly. – Krzysiek Dróżdż Jun 15 '18 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.