how to find repeated article in wordpress or in database - wordpress

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. ;)

Related

How to check if an order number exists in woocommerce?

In my WooCommerce store, I have an input field where I want the user to enter the order number. When validating this field, I need to check if that order number actually exists in WooCommerce.
From this question, it seems like the WooCommerce order_number might not always be the same as the order_id (which is always the same as the post_id).
So I can't use wc_get_order($the_order) function since the documentation states that it wants the post_id in the $the_order parameter.
I can't find a specific function to get the order by the order number (neither in the documentation nor the code in github).
I'm fairly new to WooCommerce, so maybe I am missing something. Is there a way to do this at all? Or is the wc_get_order mis-documented?
I've done a lot of googling and searching here on stack overflow, but I really can't find the answer to this! Any help is appreciated.
PS: I suppose I could get all orders and loop through them one by one checking if the number matches, but I was hoping to find a simpler solution to this :D
You may try this if statement to see if given ID (number) is an Order Number or not:
function is_it_a_shop_order($givenNumber)
{
if(get_post_type($givenNumber) == "shop_order")
{
echo "yes this is a valid order number";
}
else
{
echo "no go away";
}
}
Wordpress stores all posts (pages, orders, products etc.) in wp_posts table and orders are stored with post type named "shop_order".
I tested the code. I hope this will help you. Have a good day.
The reason you're struggling to find anything about this in the documentation is because WooCommerce has no native concept of an order number. The ID is the order number.
What store owners tend to find however is that order IDs don't increase sequentially. There can be a large jump in ID between one order and the next because of the way WordPress handles posts. Often users will install a plugin to address that. It's those plugins that introduce the differentiation between order IDs and what they refer to as the order number.
Here's an example of one such plugin: https://en-gb.wordpress.org/plugins/woocommerce-sequential-order-numbers/
Included in the documentation is an example of how to find an order by its number. If you have one of these plugins installed, you'll simply need to lookup how the plugin in question resolves numbers to IDs.
Send the order number through the wc_get_order call. If the returned array is empty, the order number does not exist.
$bOrderExists = DoesOrderExist($OrderNumber);
function DoesOrderExist($OrderNumber)
{
$orderq = wc_get_order($OrderNumber);
if(empty($orderq))
return 0;
return 1;
}

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.

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.

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.

Wordpress: How to compare 2 float values in meta_value column?

I have about 100 posts in wordpress, all with a meta_key of price and a value.
How would I go about searching through all posts with a value between 23.00 and 41.00 for example?
I know that 'meta_compare ' treats 'meta_value' as a string, so I can't use this to solve my problem. Anybody have any clues? Thanks
I would try to implement the posts_where filter, and modify the query there. It gets called right after the meta comparison is added, and it allows you to change the WHERE part of your query. You need to replace all instances of your meta key to CAST(meta_key AS DECIMAL(5,2)). I guess the meta key is prefixed by the meta table name, so check for that. You will need to figure out a way to pass two meta_value parameters if you want to do a BETWEEN query, but you can combine them with a comma and split them up in your filter. As long as a valid SQL where-clause comes out of you filter, everything should work.

Resources