8Feb/112
WordPress permalink via SQL
Today someone asked how to get the wordpress permalink from another language via SQL. Well, after a little bit of head scratching I have come up with a relatively easy way of doing this... enjoy!
SELECTwpp.post_title,wpp.guid,wpp.post_date,CONCAT(wpo_su.option_value,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(wpo.option_value,'%year%',date_format(wpp.post_date,'%Y')),'%monthnum%',date_format(wpp.post_date,'%m')),'%day%',date_format(wpp.post_date,'%d')),'%postname%',wpp.post_name ),'%category%',wpc.slug )) as permalinkFROMwp_posts wppINNER JOIN wp_options wpo on wpo.option_name='permalink_structure' and wpo.blog_id=0INNER JOIN wp_options wpo_su on wpo_su.option_name='siteurl' and wpo_su.blog_id=wpo.blog_idINNER JOIN (select wtr.object_id ID, max(wpt.slug) slugfrom wp_term_relationships wtrinner join wp_term_taxonomy wtt on wtt.term_taxonomy_id=wtr.term_taxonomy_id and wtt.taxonomy='category'inner join wp_terms wpt on wpt.term_id=wtt.term_idgroup by wtr.object_id) wpc on wpc.ID=wpp.IDWHERE wpp.post_type = 'post' AND wpp.post_status = 'publish'ORDER BYwpp.post_date DESC
update 9/2 - appended %category% join and replace
[facebook_ilike]

January 13th, 2012 - 21:15
How to append category to the above query..?
February 22nd, 2013 - 11:54
How add post type to query and permalink.
i.e: http://domain.ext/listings/my-title-here
Custom post type: listings
Thanks