I’m updating programmatically posts in a WP 3.01 install, using custom made tools.
Sometimes I do change programmatically post_status
from DRAFT to PUBLISHED using custom SELECT
queries, however this seems spoiling posts permalinks.
When in a DRAFT state, posts have the following link structure
http://myblog.com/?p=73006
Could there be some “trick” to force a change in the link structure, generating the proper permalink?
You need to programmatically set the slug as you do so. An SQL trigger could do the trick. Don’t forget to mind duplicate slugs as you write it.
Else, instead of publishing using the database, write a php script that calls the WP API.
Create a
.php
file in root of your WordPress directory and write:So this code loads all posts of
post_type=='urun'
and sets the$urun->post_name
field to empty (this field defines the post permalink slug) then WordPress automatically fills a value for you when you callwp_update_post()
. If you want to changepost_type'
to'post'
orpost_type'
to'page'
just change this line: