Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have installed wordpress with question2answer as a single signon. The database created by wordpress with wp_ prefix and question2answer prefix is qa_

Now wordpress tables doesnt required to define prefix with $wpdb-> but how can I get question2answer table without query with prefix like I prefer something like as below

$titles = $wpdb->get_results("
        SELECT title
        FROM qa_posts // with qa_ prefix
    ");

Its giving output of the title but i want something like below code where I dont have to define qa_ prefix same like wordpress default tables

$titles = $wpdb->get_results("
        SELECT title
        FROM posts // without prefix
    ");
share|improve this question
1  
Contact the authors and tell them that they're doing it plain wrong with not using $wpdb->prefix. –  kaiser Sep 21 '12 at 17:48
    
Ah! this is not the theme but other script I am using with is allowing to install into wordpress database and using wordpress authentication. So it has own db prefix and I want to fetch it into wp themes –  pixelngrain Sep 21 '12 at 17:49

1 Answer 1

Write a function that uses $wpdb->prefix as a fallback. Something like this:

function wpse65880_table_with_prefix($table) {

    // should define array in config file, rather than hard coding
    $my_tables = array("table1", "table2", "table3", "table4");

    if (in_array($table, $my_tables)) {
        // "qa_" should also be a config file setting
        return "qa_" . $table;
    }
    else return $wpdb->prefix . $table;
}

$table_name = wpse65880_table_with_prefix('post');

$titles = $wpdb->get_results("
    SELECT title
    FROM $table_name // reflects current prefix
");
share|improve this answer
    
I think you misunderstood my question dear. I want it to be use for two prefix in same table. one is default wp_ and I have few custom tables with qa_ prefix –  pixelngrain Sep 21 '12 at 17:45
1  
Yes, I misunderstood the question. BTW: I believe you are not a native English speaker, and I believe that you meant no disrespect by calling me 'dear.' However, the use of the term 'dear' appears patronizing to native speakers of American English. It's particularly disturbing to women, because endearments have historically been used to diminish the authority and respect accorded to women's participation in non-traditional arenas. It would be wise to avoid using endearments in future SE comments. –  marfarma Sep 21 '12 at 18:16
3  
Ah! I apologies, never knew these all. You are right I am not native English speaker. Also your username doesn't show that your gender. But anyway I apologies again for your incontinent and make you disturb. I will take care in future. –  pixelngrain Sep 21 '12 at 18:46
    
I updated my answer. There is no built-in way to tell wordpress to use an alternate prefix for non-native tables. –  marfarma Sep 21 '12 at 18:50
1  
my reference to the config file was not meant to refer to wp_config.php --> you can use any file in your theme to store this information. You can even store it in a database. I only meant to suggest that you do some more work, on your own, to figure that bit out - rather than just copy what I put there. –  marfarma Sep 21 '12 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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