• Resolved jradford

    (@jradford)


    I am using the “Replace the file, use new file name and update all links” option and after uploading the file, the link isn’t getting updated in the main content of a page.

    I debugged a bit and found the issue was occurring in upload.php -> during the db prepare to update the post_content field. The $wpdb->prepare was failing, so the $sql variable was empty, as I was getting empty query errors for the actual call to $wpdb->query( $sql )

    So, I changed the following original lines of code:
    $post_content = $rows[“post_content”];
    $post_content = addslashes( str_replace( $search_urls, $replace_urls, $post_content ) );

    $sql = $wpdb->prepare(
    “UPDATE $table_name SET post_content = ‘$post_content’ WHERE ID = %d;”,
    $rows[“ID”]
    );

    To the following code:
    $post_content = $rows[“post_content”];
    $post_content = str_replace( $search_urls, $replace_urls, $post_content );

    $sql = $wpdb->prepare(
    “UPDATE $table_name SET post_content = %s WHERE ID = %d;”,
    array($post_content, $rows[“ID”])
    );

    After the change was made, the query to update the page_content started working and the links in my content were getting updated on a replace.

    I hope this is a viable implementation and can be adopted in the next update. I can supply the (extremely) long source of the content page if needed.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Links not being updated during replace (with possible dev fix)’ is closed to new replies.