WordPress.org

Ready to get started?Download WordPress

Forums

How do you search for the $table_prefix in a Plugin?? (2 posts)

  1. Ragnar1337
    Member
    Posted 3 years ago #

    From the wp-config.php file....

    $table_prefix = 'WHATEVER';

    How do you make a plugin check for a $table_prefix like WHATEVERposts?

    http://wordpress.pastebin.com/LegUYW2L

    It works just fine if you don't have a $table_prefix, but not if you do have one.

    $wpdb->prefix
    doesn't work since there's
    $wpdb->query

    How do you make it work both with and with out a prefix?

  2. Ragnar1337
    Member
    Posted 3 years ago #

    I got it...

    <?php
    /*
    yacka yacka yacks

    */

    function simpleDP(){
    global $wpdb;
    $wpdb->query("DELETE FROM $wpdb->posts
    USING $wpdb->posts, $wpdb->posts as vtable
    WHERE ($wpdb->posts.ID > vtable.ID)
    AND ($wpdb->posts.post_title=vtable.post_title)");

    }
    add_action('publish_post', 'simpleDP');

    function OptimizeDaDatabase(){
    global $wpdb;
    $wpdb->query("OPTIMIZE TABLE $wpdb->wp_smartfeed");
    $wpdb->query("OPTIMIZE TABLE $wpdb->ak_twitter");
    $wpdb->query("OPTIMIZE TABLE $wpdb->comments");
    $wpdb->query("OPTIMIZE TABLE $wpdb->links");
    $wpdb->query("OPTIMIZE TABLE $wpdb->options");
    $wpdb->query("OPTIMIZE TABLE $wpdb->postmeta");
    $wpdb->query("OPTIMIZE TABLE $wpdb->posts");
    $wpdb->query("OPTIMIZE TABLE $wpdb->term_relationships");
    $wpdb->query("OPTIMIZE TABLE $wpdb->term_taxonomy");
    $wpdb->query("OPTIMIZE TABLE $wpdb->terms");
    $wpdb->query("OPTIMIZE TABLE $wpdb->users");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wp_smartfeed");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wpo_campaign");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wpo_campaign_category");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wpo_campaign_feed");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wpo_campaign_post");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wpo_campaign_word");
    $wpdb->query("OPTIMIZE TABLE $wpdb->wpo_log");
    }
    add_action('publish_post', 'OptimizeDaDatabase');
    ?>

    and optimizes the tables at the same time.

Topic Closed

This topic has been closed to new replies.

About this Topic