RadicalM1nd RadicalM1nd - 1 month ago 4
MySQL Question

Exporting post names in SQL, then reusing them [Wordpress/Woocommerce/SQL]

I am trying to fill the description of around 100 Products in a Woocommerce Wordpress site via SQL, however I am fairly new to the SQL language and facing some troubles. I have already figured out how to fill the description, like so:

UPDATE wp_posts SET post_excerpt = '%description goes here%' WHERE post_type = 'product'


However, here is where I'm facing problems: I am trying to GET all the Product Names (wp_posts with type product) and want to re-use them in the above mentioned update query. As a very basic example, i would like to try to set all descriptions to "This is the description for %productTitle%".

I already have something like this:

SELECT DISTINCT
post_title
FROM wp_posts
WHERE post_type = 'product'


But how do i save the returned titles in variables to reuse with my first query?

Thanks in advance!

Answer

However, here is where I'm facing problems: I am trying to GET all the Product Names (wp_posts with type product) and want to re-use them in the above mentioned update query.

You don't need re-use any data. If you want update that column massively, you can use CONCAT function to concatenate strings.

UPDATE wp_posts SET post_excerpt = CONCAT('This is the description for ',productTitle) WHERE post_type = 'product'
Comments