mardi 17 novembre 2015

Need to change values in MySQL Database, having trouble with SQL language

I'm developing a website and there is a lot of manual work I have to do (clicking pages and setting templates etc) so I thought why not automate it. I have logged into PHPMyAdmin and have located the places in my MySQL database that I want to alter.

It consists of two parts, being 'wp_postmeta' and 'wp_posts'. I have a text file with all the 'post_id' that I want to access as well as the content that I want to change the page to. I can convert this to an arrat if necessary.

SELECT * 
FROM `wp_postmeta` 
WHERE `post_id` =x
AND `meta_key` LIKE '_wp_page_template'
AND `meta_value` LIKE 'template-blank-4.php'

SELECT*
FROM `wp_posts`
WHERE `post_id` =x

What I'm trying to do is do a loop or else a series of if/else statements where can access my post number and set its page content. I would perform the two actions (being setting the content and setting the page template) separately. How do I start?

Here is an extremely rough eapmle of what I want to achieve;

Array =(1,2,3,4...1200)
Array2=("string1", "string2", "string3"..."string1200")
for (array[i], i<1200) {
SELECT*
from 'wp_posts'
where post_id=i
set post_content="array2[i]"
SELECT*
from 'wp_postmeta'
where post_id=i
AND `meta_key` LIKE '_wp_page_template'
SET `meta_value` TO 'template-blank-4.php'
}

Any help with this would be greatly appreicated



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire