data (html) migration to posts

So I solved my problem using the wp_insert_post($array) but before I used wp_insert_post() I had to remove a filter as shown below. remove_filter(‘content_save_pre’, ‘wp_filter_post_kses’); remove_filter(‘content_filtered_save_pre’, ‘wp_filter_post_kses’); // Add code to insert post(s) with html elements here $post = array( ‘post_content’ => ‘<a href=”#” title=”text”>text</a> some random text’, ); wp_insert_post($post); // Then add the filters back … Read more

#1115 – Unknown character set: ‘utf8mb4’

WordPress does not support MySQL 4 : To run WordPress your host just needs a couple of things: MySQL version 5.0 or greater (recommended: MySQL 5.5 or greater) https://wordpress.org/about/requirements/ While the utf8mb4 encoding is recent change and you might work around it, overall you still need compatible MySQL version.

Create table from array with prepare

I tried this in local, and I think you have multiple fields inside $fields so I’ve added them in array. Just look at the code below; it works fine as tested: add_action(‘your_hook’, ‘createTableFromFields’); function createTableFromFields($tablename) { $wpdb = $this->db; $tablename = $wpdb->prefix . $tablename; $fields = array(‘PersonID’,’LastName’); $sql=”CREATE TABLE IF NOT EXISTS %s (id INT(6) … Read more

Fetching values from database for select box

You can used below code to get results from the database in wordpress. global $wpdb, $posts; $prefix = $wpdb->prefix; $query = $wpdb->get_results(“SELECT * FROM {$prefix}states”); if($query){ echo ‘<select><option value=”select”>Select</option>’; foreach ($query as $value) { echo ‘<option value=”‘.$value->ID.'”>’.$value->ID.'</option>’; } echo “</select>”; }