Below is a DB query I am using to retrieve values and place them in a WP_List_Table. Values are currently being added by add_option
, then those values are converted into a custom database table called wp_testimonials
. I have no clue why I did it this way, but it works!
So now I need to create a conditional that says "if user is currently updating the option, then update the table after the option is updated, else don't do anything."
However, I do not know how to state this condition. My display table is located in a different file than where the options are being updated.
Below is the database query, which is currently updating every time I access the page and needs to be changed.
$options = get_option('testimonials_settings');
if ( isset ($options)) {
global $wpdb;
$table_name = $wpdb->prefix . "testimonials";
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name tinytext NOT NULL,
company_name text NOT NULL,
company_url text NOT NULL,
testimonials_quote text NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$name = $options['testimonials_name'];
$company_name = $options['testimonials_website_name'];
$company_url = $options['testimonials_website_url'];
$testimonials_quote = $options['testimonials_quote'];
$rows_affected = $wpdb->insert( $table_name, array( 'name' => $name, 'company_name' => $company_name, 'company_url' => $company_url, 'testimonials_quote' => $testimonials_quote ) );
}