Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Correct way to select db table in WP plugin

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #207229
    ravensjeff
    Participant

    So I have a WP plugin that one of my devs built some time ago which has some php like this:

    foreach ((array)$docs as $key => $file)
        {
            if ((int)$file === 0)
            {
                $results = $wpdb->get_var($wpdb->prepare(
                    'SELECT id FROM wp_posts WHERE guid = %s',
                    $file
                ));
    
                if ((int)$results !== 0)
                {
                    $settings['docs'][$type][] = (int)$results;
                }
            }
            else
            {
                $settings['docs'][$type][] = (int)$file;
            }
        }
    

    Problem is that the database prefix has been changed by the Security plugin. I know that I can update wp_posts above with the new prefix such as abcdef_post, but there’s gotta be a more appropriate way of doing this in a plugin. What is proper in this case?

    #207241
    ravensjeff
    Participant

    I believe I found my own answer:

    $wpdb->prefix

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.