/** * Add column if table column not exist. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @param string $db The table name. * @param string $column The column name. * @param string $column_attr The column attributes. */ function geodir_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL") { global $wpdb; if (!geodir_column_exist($db, $column)) { if (!empty($db) && !empty($column)) { $wpdb->query("ALTER TABLE `{$db}` ADD `{$column}` {$column_attr}"); } } }
/** * Add column if table column not exist. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @param string $db The table name. * @param string $column The column name. * @param string $column_attr The column attributes. */ function geodir_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL") { global $wpdb; $result = 0; // no rows affected if (!geodir_column_exist($db, $column)) { if (!empty($db) && !empty($column)) { $result = $wpdb->query("ALTER TABLE `{$db}` ADD `{$column}` {$column_attr}"); } } return $result; }
/** * Save or update post custom fields. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @param int $post_id The post ID. * @param string $postmeta Detail table column name. * @param string $meta_value Detail table column value. * @return void|bool */ function geodir_save_post_meta($post_id, $postmeta = '', $meta_value = '') { global $wpdb, $plugin_prefix; $post_type = get_post_type($post_id); $table = $plugin_prefix . $post_type . '_detail'; if ($postmeta != '' && geodir_column_exist($table, $postmeta) && $post_id) { if (is_array($meta_value)) { $meta_value = implode(",", $meta_value); } if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET " . $postmeta . " = '" . $meta_value . "' where post_id =%d", array($post_id))); } else { $wpdb->query($wpdb->prepare("INSERT INTO " . $table . " SET post_id = %d, " . $postmeta . " = '" . $meta_value . "'", array($post_id))); } } else { return false; } }