We are trying to retrieve HTML code stored as a LONGTEXT in an UTF8 MySQL table then store this as a post meta value in WordPress.
If the HTML contains a pound (£) symbol for example then the ‘update_post_meta’ function does not store data correctly, this occurs for only some characters / for example is fine.
The issue does not exist when saving these characters through the wp_update_post function.
The code below is the page that we are using for processing the data the function in question is updatecdata()
function updatecdata()
{
$SERVER = 'REDACTED';
$USERNAME = 'REDACTED';
$PASSWORD = 'REDACTED';
$DB = 'DATABASE';
$link = mysqli_connect($SERVER,$USERNAME,$PASSWORD,$DB);
mysqli_select_db($link, $DB);
$sql="SELECT * FROM table;";
$result = mysqli_query($link, $sql);
if(! $result ) {
die('Could not get data: ' . mysqli_error($result));
}
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$post_id = $row["post_id"];
$post_title = $row["post_title"];
$post_content = $row["post_content"];
$post_content_reg = row["post_content_reg"];
#####update data####
$post = array(
'ID' => $post_id,
'post_title' => $post_title,
'post_content' => $post_content
);
//UPDATE POST
wp_update_post($post);
//UPDATE POST_META
update_post_meta($post_id, 'contentreg', $content_reg);
}
mysqli_close($link);
}
Overall Fee in (£)
– Aspurian Jan 04 '19 at 12:05Overall Fee in (£)
'; then everything works as expected it seems when we try and retrieve from the table the problem creeps in – Aspurian Jan 04 '19 at 12:06