How to export WordPress comments with post informations - wordpress

I need to export all the comments on a WordPress website but I also need to have the post title of the currrent comments being exported.
Surprisingly none of the popular WP plugins seems to offer this possiblity. How would you do that?
I was thinking working with 2 sheets in Excel as I am capable to export the comments in one CSV and my posts in an another, but it seems really complicated for my current need.
I was hoping exporting one CSV file only in which I would have automatically the comment's informations but also the related post's informations.
Thanks in advance.

You can export Wordpress comments with post informations in PhpMyAdmin.
This simple Query will be a good starting point:
SELECT DISTINCT wp_comments.comment_ID, wp_comments.comment_post_ID,
wp_comments.comment_author, wp_comments.comment_author_email,
wp_comments.comment_author_url,
wp_comments.comment_author_IP,wp_comments.comment_date,
wp_comments.comment_content, wp_posts.ID, wp_posts.post_title
FROM `wp_comments` INNER JOIN `wp_posts`
WHERE wp_comments.comment_post_ID = wp_posts.ID
Up to you then to select the columns you want to export.

Related

Where are the Yoast SEO titles and descriptions stored?

I'm managing a small directory website and I have set some generic titles and descriptions for my pages with Yoast SEO Plugin.
I'd like to duplicate them to every entry/page directly via the MySQL database. However, I cannot find it in the DB.
I didn't find it in wp_postmeta, wp_posts or wp_yoast_seo_meta.
That's why I ask: where does Yoast (v. 7.8) store the SEO informations that a user set?
So after some time, I figured out that the best way to find out where this data where stored was to dump the DB and look in that dump:
mysqldump -u wordpress --no-create-info --extended-insert=FALSE wordpress -p > dumpydump.sql
cat dumpydump.sql | grep "What you're looking for"
What you'll find is an row called wpseo_taxonomy_meta in table wp_options which contains every taxonomy SEO texts. It is saved as a PHP serialised value.
Be careful though that this is just for the SEO texts of the Taxonomies (e.g. Location, Feature, Category...). It doesn't apply to the SEO descriptions and titles of the posts themselves (these are stored in wp_postmeta with at least one row per post).
Yoast SEO Save Description and Keywords in wp_yoast_indexable Table. Where you can see column name description and keywords
just use this code, you'll get an array of all settings that Yeast SEO show under "Search Appearance" page. Including title, descriptions and all other settings.
$wpseo_search =get_option( 'wpseo_titles', $default = false );
Update your required field and save using the update_option() function of WordPress.
You can use this (for categories):
$wpseo_options = get_option( 'wpseo_taxonomy_meta');
$wpseo_options['category'][<the_category_id>]['wpseo_title'] = '... my title';
$wpseo_options['category'][<the_category_id>]['wpseo_desc'] = '... my description';
update_option('wpseo_taxonomy_meta', $wpseo_options, true);
It should work. Also, you should check the wp_yoast_indexable table for correct recordings.

In WordPress, should it be possible change a word in all pages of a site in once time?

I know it sounds crazy, but as asked above, i have lots of pages with the word "Vocal" between and tags and i would like to change this word to "Voices". Make it one page by one would be very tiring and take a lot of time. If it is not possible, "Vocal" should remain as it is. Thanks for any help!
My suggestion would be to export your WordPress database to a .sql file.
(possibly you would only need to export your wp_posts table, if you only really need to replace it in the page/post content and nowhere else in your entire site)
Then open it in a text editor of your choosing and do a find replace.
Search for %Vocal%
Notice the the % symbol, just replace them with a blank space.
Then do a replace with %Voices%.
After you are done save the .sql file and import it to your database.
Of course keep an original backup of the file, in case anything goes wrong :)
First backup your database! Then run the SQL command
update wp_posts set post_content = replace( post_content, 'Vocal', 'Voices' );
Try https://wordpress.org/plugins/search-regex/ It hasn't been updated in a while, but it works. You can find/replace with either grep or plain text in post content, post meta, etc. No reason to use PHPMyAdmin or run database queries. Backup your database first.

Move taxonomies to a new post type

I have a strange situation where I need to move current taxonomies from one post type to a new one in Wordpress.
If I change the taxonomy post type within the functions I am losing all categories and relationships.
You should change the ID's in the database, take a long look at the phpmyadmin
wp_term_taxonomy
wp_terms
wp_term_relationships
In the terms table you will find the id of the old and new taxamonies
in term_taxonomy replace all old term_id with the new.
SQL:
UPDATE `wp_term_relationships` SET `term_id` = REPLACE(`term_id`, /*old id*/, /*new id*/);
Do make a backup before you start.
Source: Here
While #uvishere is right with his answer when you have a lot of categories to deal with that process can be a real headache.
What I have done is I created the taxonomies keeping their previous names under the new post types. Wordpress however will not add the new categories to these new post types once I uploaded the code but I then removed the old taxonomies from the code and all categories shifted under the new post type keeping the id's relationships ecc.. which was great and fast!
Now all I had to do is move the posts from one post type to the other and I have done so using the Post Type Switcher plugin

how to find repeated article in wordpress or in database

I accidentally put some articles in WordPress which is already there, Now it's hard for me to find out. Is there a easy way to do it?
I don't know too much about database, Can I use phpMyAdmin find out?
If the articles have for example exactly the same titles, you can get list of article IDs having the same title with:
SELECT post_title, COUNT(post_title), GROUP_CONCAT(id SEPARATOR ', ')
FROM wp_posts
GROUP BY post_title
HAVING ( COUNT(post_title) > 1 );
You can modify post_title to be any other field that you know to indicate the duplicates.
You can use phpMyAdmin, too, since it has an option to make SQL queries. Once you find duplicate rows, just remember to leave one of them there. ;)

Tag all Wordpress posts

I've been searching for hours, either for a plugin or some safe looking SQL to do this, but nothing seems to be exactly what I need...
I have a Wordpress site of approximately 32,000 posts, and we use various tags to help with administration on the back end (i.e. they're not visible on the front end or used for SEO, before anybody comments on too much usage of the same tag). About 30,000 of these posts include the tag 'new', but we need to now tag the remaining ~2,000 to match.
The WP administration panel isn't really up for the task - it would take somebody days to go through and apply a tag to 2,000 posts. Various plugins seem to exist but they don't really do what they claim in the descriptions. And the only SQL I could find that seemed helpful assumes that the tag is new and that I want to apply it to all posts in a single category. I suppose I could delete the existing tag (again, not a fun task with Wordpress' admin panel - it generally crashes after about 30 posts meaning somebody has to sit clicking the button over and over) and then run the SQL to apply a new.
Can somebody point me in the right direction please?
You could run a loop over all of your posts and use wp_set_object_terms() to add the desired tag:
http://codex.wordpress.org/Function_Reference/wp_set_object_terms
I had this problem today too. I tagged all of my posts with the following SQL. (Replace <prefix> with your DB prefix and "GlobalTag" with whatever you want your tag name to be.)
# create a term which will be your new tag
INSERT INTO <prefix>_terms (name, slug) VALUES ("GlobalTag", "global-tag")
# this is what defines the term as a Tag vs Category vs Video Category, etc
# only do this if you are creating the category through SQL, not the GUI
INSERT INTO <prefix>_term_taxonomy (term_id, taxonomy, count)
SELECT
(SELECT term_id from <prefix>_terms AS term WHERE term.name="GlobalTag") as "term_id",
"tag" as "taxonomy",
(SELECT COUNT(*) FROM <prefix>_posts AS posts WHERE (posts.post_status IN ("publish", "draft")) AND LENGTH(post_content) > 25) as "count"
# now tag every post with GlobalTag
INSERT INTO <prefix>_term_relationships
SELECT
id as "object_id",
(
SELECT term_taxonomy_id
FROM <prefix>_term_taxonomy AS term_tax
INNER JOIN <prefix>_terms ON <prefix>_terms.term_id = term_tax.term_id
WHERE <prefix>_terms.name="GlobalTag"
) as "term_taxonomy_id",
0 as "term_order"
FROM <prefix>_posts AS posts
WHERE (posts.post_status IN ("publish", "draft")) AND LENGTH(post_content) > 25
NOTE: you may want to tweak the posts query in here. This tags all posts that are published and/or drafts and that have content that is longer than 15 words.

Resources