Mysql Query to replace WP post title with all_in_one seo post title
I want to replace the post title with seo title if it exists
I would like to include $wpdb->wp_postmeta.meta_value WHERE $wpdb->wp_postmeta.meta_key = aioseop_title
in the query below.
Ideally, I'd like to list the post_title everytime, and include the $wpdb->wp_postmeta.metavalue
if the meta_key = aioseop_title
for each post.
What this is doing: Below it's finding the post id to build a google news sitemap.
What I'm proposing above will use the seo title instead of the default post title in wordpress.$rows = $wpdb->get_results(
"SELECT
$wpdb->pos开发者_C百科ts.ID
, $wpdb->posts.post_date_gmt
, $wpdb->posts.post_title
FROM $wpdb->posts
WHERE $wpdb->posts.post_status='publish'
AND (DATEDIFF(CURDATE(), post_date_gmt)<=30)
$includeMe
ORDER BY $wpdb->posts.post_date_gmt DESC
LIMIT 0, 1000"
);
After reading the comments to clarify, something like this perhaps?
$rows = $wpdb->get_results(
"SELECT
$wpdb->posts.ID
, $wpdb->posts.post_date_gmt
, $wpdb->posts.post_title
, meta.metavalue
FROM $wpdb->posts
LEFT JOIN $wpdb->wp_postmeta.metavalue AS meta ON meta.post_id = $wpdb->posts.ID AND meta.meta_key = 'aioseop_title'
WHERE $wpdb->posts.post_status='publish'
AND (DATEDIFF(CURDATE(), post_date_gmt)<=30)
$includeMe
ORDER BY $wpdb->posts.post_date_gmt DESC
LIMIT 0, 1000"
);
Followed by a conditional in php to determine if the aioseop (probably $row['metavalue']) column is null or not. I've not delved deep enough into wordpress to know the exact column names but from what you've put up this is probably what you're looking for. (As an aside it would probably be easier for you to alias the 'FROM $wpdb->posts' part as well.
精彩评论