I've made a website using ACF and all the content has been copied over from the default WordPress editor, to the new ACF fields.
The trouble is my client didn't delete the content from the default WordPress editor as they went along. Subsequently, it's causing loads of broken links.
Long story short, is there a way to delete all content from the default post editor site wide, rather than update every single post?
To Delete all content from Wordpress posts you will need to export all posts ID in a CSV file.
In PhpMyAdmin you could use
SELECT ID FROM `wp_posts`
Then export the query result in a CSV file. Open the CSV and create a new column for the content which you want empty.
To test my answer, I installed the free version of the 1st WordPress plugin I found for the search query csv import on https://wordpress.org/plugins/
Then on your WordPress dashboard go to this newly installed plugin menu and import the CSV file previously created.
Let the importer update existing posts and define the content as the only column to update.
Before updating All content, I would make a test of the importer configuration on 1 unpublished test post to make sure ACF field aren't emptied with the import.
Which may not happen if you don't miss a configuration on the importer.
In MySQL this is a straight task for deleting all content from the default post, i.e using PHPMyAdmin, SQL section after selecting WP database (i.e find name in wp-config.php):
DELETE * FROM wp_posts
DELETE * FROM wp_postmeta
Please note this will remove definitively ALL content from your website, always take a backup.
You can also find a manual plugin for doing this here.
Related
I have a rather large spreadsheet that lists out all the images on a client site along with the image URL. It has updated information for the image alt attributes as well as new captions.
Since the list is so large, I'm looking for something like an SQL query or something I could run that would import the necessary information from the spreadsheet and update the related image metadata in the database. I'm not a backend guy, but the guy who usually handles this kind of thing is unavailable for a while, so it's fallen to me. Is this something I can do in MySQL?
edit: I found this post that deals with what seems to be a similar issue. Would I be able to use this method for the image captions?
In case anyone happens to want to solve a similar issue, here's how I solved it.
This post details where alts and captions live in the WordPress database: https://wordpress.stackexchange.com/questions/1777/are-captions-stored-anywhere. I used that as the basis for my process.
First, I ran the following query on the wp_postmeta table and copy/pasted the results into a new sheet in my spreadsheet.
SELECT * FROM 'wp_postmeta' WHERE meta_key LIKE '_wp_atttached_file'
Second, I ran a similar query on the table wp_posts and also put the results in a new sheet.
SELECT * FROM 'wp_posts' WHERE 'post_type' LIKE 'attachment'
I then used a Google Sheets (the spreadsheet software I'm using) add-on to merge each sheet with my main sheet. The posts data I merged on the basis of matching URLs (the data I have to work with in my original spreadsheet). Then I merged the postmeta data based on matching post IDs.
Finally, once I had all of that, I could download my file as a .csv file and import it into the postmeta and posts tables. I made sure to do my first import on a local install of the site so as to not screw with a live site. I'm using Sequel Pro for managing databases, and it has a handy CSV import tool that allows you to do an UPDATE on the postmeta and posts tables. My import used the post IDs and meta_key (for the alts) and post_ID/ID (for the captions) to match up the data.
That's the process that worked for me, though I still did have a dozen images with funky URLs that I just updated manually rather than messing around with Regex.
Every year we update our posts with new data. For example, the best places to live in 2018.
I am trying to write a python script this year that updates the post_content in mysql so we don't have to do a bunch of copying and pasting into the html post editor.
However, as a test, I manually updated wp_post in phpmyadmin for one article. After updating, the following happens:
The mysql table correctly updates. I can export the table with the changes and they are all in there.
The LIVE article is updated.
However, when I go to edit the article in wordpress's post editor, it's still showing the previous version.
Therefore, if I save the post in post editor, it will revert back to the old version.
I am completely out of ideas. I've been googling for hours and no one seems to
have this problem.
More background on my setup:
Wordpress version 4.9.1
Using dreampress from dreamhost as the host
Here's a link to the working page:
https://www.homesnacks.net/best-places-to-live-in-georgia-122131/
Ended up hooking into the wordpress API:
https://developer.wordpress.org/rest-api/
And these tutorials helped
https://www.cloudways.com/blog/setup-and-use-oauth-authentication-using-wp-rest-api/
https://discussion.dreamhost.com/t/authenticating-to-the-wordpress-api-using-oauth-1-0a-server/65094
I am making a copy of a WordPress website on another server. Everything is OK in copying the database.
However, I need to replace the old domain name "old.com" with "new.com" in some MySQL tables. I am using the following query:
UPDATE wp_options SET option_value = REPLACE(option_value, 'https://old.com/', 'http://new.com/')
This works for a lot of things (like the site URL), however, it breaks all my CSS modifications to the template and all my options, it's sort of restored into default settings directly after I run the previous command.
What could be the reasons?
When moving a Wordpress table the Database Search and Replace Script by interconnect/it does the job very well.
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
The software is designed for exactly the purpose of replacing olddomain.com with newdomain.com.
All you do is extract Search Replace DB to it's own directory off the root of the Wordpress installation. You then run
newdomain.com/Search-Replace-DB-master
This will automatically find your Wordpress database and will provide search and replace field. It allows a dry run where you can check the results before doing the live run.
Hope this is useful. I have used this many times when changing the domain for a Wordpress installation and it works every time.
Never manually replace URL use https://wordpress.org/plugins/velvet-blues-update-urls/ plugin to safely search & replace old URL with new one.
I'm exporting an old release 1.9.2 and importing to 3.0.2.
Each module has dozens of videos that I play via an URL/link, which points to my own .PHP program on the site (and that wraps a Camtasia video).
I found that in 3.0.2, the link opens on a separate page, unless I edit each link by going to "Appearance", then "Display" and setting it to "Embed".
So I would like to write a mySQL update script to automatically set this flag for all such links (I will add a where clause to my script name).
I checked database in PHP/MyAdmin, and didn't see any likely table names.
You should attempt to use the admin tools to update everything, go to your moodle installation's main URL.
Then go to the site administration. After /admin in the url, add /tool/replace and go there.
You can there enter what you want to find in the db, and replace it with another value. Just be carefull with this tool and make a backup before you begin.
I have a slight problem with a wordpress migration. I've bulk uploaded posts from csv on my local WAMP server as it's faster and then uploaded & imported a SQL dump to the remote server.
In the guid column of the wp_posts table, it contains the url of the post - I presume (might be wrong, please correct if I am) this is the same as the 'permalink' setting when you edit a post - and all of them are http://localhost/post-name/ which is fine for now, I'm happy to work on an SQL query to replace if needed.
I've uploaded the SQL dump and it still shows 'http://localhost/post-name' in the remote server db as expected. However when I search for a post on the frontend, just to make sure it's picking up the posts OK, I was expecting the links to give me a 404 error until I changed the links, but they don't - they point nicely to the http://remoteserver.com/post-name/
Where as it's a nice problem to have as it still works - I was wondering why & do I need to change it? I prefer to not mess with the db if at all possible.
When migrating, you might need to define your wordpress url in wp-config.php, and I recommend find and replacing the database with this tool. It's pretty neat, because it pre-populates your database from your config file. Obviously, you'd replace http://localhost/ with http://www.yoursite.com/
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');