Where are the Yoast SEO titles and descriptions stored? - wordpress

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.

Related

How to export WordPress comments with post informations

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.

Recover Custom Post Type Data

I have created CPT using CPT UI plugin and suddenly I lost all the important data. I don't have any backup and I need it backup. Is there any I can get it backup? I have SQL backup of last week.
Moreover I am seeing Count on CPT categories but they are showing Empty on main CPT page. for example CPT:
Animals --> showing (0) posts
Animal Categories is showing 100 counts that means It has data but something has hide it. I remember I updated Permalinks but I don't remember the previous settings
use this sqlQuery in your SQL Database (phpMyadmin or ...) and you will get a list of your custom post type posts with their info:
SELECT *
FROM {table prefix}_posts
WHERE post_type = 'your_custom_post_type_name'
AND post_status = 'publish'
your {table prefix} can be wp or some thing else if you've change it on wp setup step you can check it in your Database or wp-config.php file in your wp root.
you can replace * in query with whatever field name you want for example:
post_content, post_title, post_excerpt
to only get fields that you need.

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.

Is it possible to convert wordpress custom post type to normal categories

Currently our site's videos are posted as custom post type. We have totally changed the theme and added so many new features. For our new site we are trying to change videos to category. (Custom post type to normal categories). Is this possible. I have exported the custom post type as XML file, but I don't know how to change it to categories.
Finally an answer. Before I start These are the conditions I'm using.
The Custom posttype (called video) need to be merged into the default post
Video's has it own custom categories, who needs to be merged into the default categories
All Video's need to get a category video, the old categories need to be children of the newly created video category.
Step Zero: BACKUP my sql BACKUP
First create a the video category in the default posttype. Note it's ID (it is found in the category edit page in the url under tag_ID. I'm assuming ID 4 in my examples
Second we assign this category to the video posttype with the following Sql:
INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`)
SELECT `ID`, '4' FROM `wp_posts` WHERE `post_type` = 'video';
Next we assign the existing custom categories as children. You need the video category slug, found on the custom-category page agian in the url with taxonomy.
UPDATE `wp_term_taxonomy` SET `parent` = 4, `taxonomy` = 'category' WHERE `taxonomy` = 'VIDEO CATEGORYSLUG';
The last step is assigning the normal posttype to the custom posttype.
UPDATE `wp_posts` SET `post_type` = 'post' WHERE `post_type` = 'video';
Now it should be done and everything should be merged. So TEST TEST TEST.
After that the code making the posttype can be disabled.
This should work, if you have questions just ask.

How can one reset the post views on a specific Wordpress page?

How can one reset the number of post views in order to remove a specific page from appearing in the "Popular" pages Wordpress widget?
Late to the party, I know, but I needed to figure this out today, which I did. So in case anyone else needs to know (for reference, I'm running WordPress version 3.3.1):
Page views are stored in the wp_postmeta table with a meta_key of post_views_count. Here's the query I used to find the views of a single post:
SELECT * FROM 'wp_postmeta' WHERE 'meta_key' = 'post_views_count' AND 'post_id' = 1234
The query returned 2 results. I'm not sure why, but setting the meta_value of both to zero did the job for me.

Resources