• The Codex article on Giving WordPress its Own Directory is very helpful.

    However, when I made the decision to do this after the site had been running for awhile, I found there was one more step that I needed to perform.

    This may be obvious, but just in case it’ll be helpful to anyone, here’s what I found.

    Let’s assume that any images, files, etc. that were uploaded while the site has been running were uploaded to the default location:

    wp-content/uploads/

    [This can be changed in Options > Miscellaneous.]

    After the move as described in the Codex article, the addresses for those items will be, for instance,

    http://mydomain/wordpress/wp-content/uploads/05/07/pix.jpg

    but any page that references that uploaded file will still think that its address is

    http://mydomain/wp-content/uploads/05/07/pix.jpg

    Here are a few thoughts on resolving this:

    1. If it’s just a few files, it may be easiest to use phpMyAdmin and edit the wp_post table: for each row where post_type=”attachment” change the guid field to be the correct address.

    2. If that’s too much hassle, then
    a. In Options > Miscellaneous, set the upload folder to
    ../wp-content/uploads, and
    b. In the file system create a directory wp-content at the same level as the directory wordpress and move wordpress/wp-content/uploads to wp-content/uploads.

    3. #1 is awkward and #2 can be confusing since it results in two wp-content directories. To avoid this problem in the future, I’ll probably install with the upload directory set to
    ../uploads
    i.e. a directory at the same level as the one containing the WordPress core files. That’ll have the side effect of insulating those files from any WordPress upgrades — leaving the wp-content directory with just plugins and themes (which I can maintain much more easily than the uploaded files).

    Does anyone see any arguments against #3? Other comments?

Viewing 6 replies - 1 through 6 (of 6 total)
  • There’s #4:
    Get the search and replace plugin and fix the links directly in the database (but backup first!).

    Thread Starter converting2wp

    (@converting2wp)

    All I found through wordpress.org/extend/plugins was the Text Replace plugin, that seems to do the replace “on the fly” at runtime, not in the database.

    Searching further: Search and Replace plugin. Is that the one you meant? Looks like it’ll do the job.

    Thanks!

    Thread Starter converting2wp

    (@converting2wp)

    From the docs, the Search and Replace plugin doesn’t actually seem to help here — since the bits I want to change are in a database field that it doesn’t seem to reference. I suppose it wouldn’t be hard to hack the plugin to look at the guid field as well, but since this all came up because of a move of the WordPress files from one place to another in the directory tree, I solved the problem this way:

    0) Ensure no one’s accessing the system.
    1) Export the database to SQL before(checking the “Add Drop Table” option)
    2) Edit the SQL directly to change all the old path names to new
    3) Import the modified SQL.

    Your shouldn’t be focusing on guid – you don’t need to change them. Read:
    http://wordpress.org/search/guid?forums=1 (Otto42 and Kafkaesqui have pretty clear explanations!)

    So, replace the path for images in the posts, and you are done.

    Thread Starter converting2wp

    (@converting2wp)

    Moshu – thanks (as always!) – but your link above points to a search on all support topics referencing guid, and I’m not sure I’ve picked out the right ones.

    My case is similar to the discussion of “moving a site from test to production” (see this post on the hackers list) that’s from a hackers thread referenced by HandySolo this support discussion

    In addition, I’m specifically concerned about the address of uploaded files. In this support discussion, Kafakaesqui says

    With that said, there is the issue of file attachments (images or other files uploaded through the post editor), which *can* run into problems due to the guid. I have a plugin that relies on it, and have been thinking through a possible tool to update the field.

    I guess I understand that the guid is an ID, not an address, though I’ll still probably change it when moving from development to production. As for the issue of the path to uploaded files, I’ll look at that again.

    Thanks!

    Thread Starter converting2wp

    (@converting2wp)

    Okay, cancel all of that – apologies for taking the space.

    Of course, it’s the address in the post_content that needs to change — and so the Search and Replace plugin very well might be the right solution.

    My mass edit of the SQL file worked, but the change to the guid field was irrelevant. It was the change to the post_content that made the difference.

    The only problem I’ve found with leaving the guid unchanged comes when trying to reuse the old files in a new post. The uploader (in v 2.0.7) does use the guid field to find the file.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to move attachments when moving an existing install to its own directory’ is closed to new replies.