Mysql 查询将 WP 帖子标题替换为 all_in_one seo 帖子标题

发布于 2024-11-01 06:39:33 字数 818 浏览 0 评论 0原文

我想用 seo 标题替换帖子标题(如果存在)

我想包含 $wpdb->wp_postmeta.meta_value WHERE $wpdb->wp_postmeta.meta_key = aioseop_title 在下面的查询中。
我不确定的是使用什么代码来查找它是否存在。
对于某些帖子,没有 aiooseop_title。

理想情况下,我希望每次都列出 post_title,并包含 $wpdb->wp_postmeta.metavalue(如果每个帖子的 meta_key = aioseop_title)。

这是做什么的:下面是查找帖子 ID 来构建 Google 新闻站点地图。
我上面的建议将使用 seo 标题而不是 WordPress 中的默认帖子标题。

$rows = $wpdb->get_results(
  "SELECT 
     $wpdb->posts.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"
);  

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.
What I'm unsure about is what code to use to find if it exists or not.
For some posts, there is no aioseop_title.

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->posts.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"
);  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味超标? 2024-11-08 06:39:33

阅读评论澄清后,也许是这样的?

$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"
);  

接下来是 php 中的条件,以确定 aioseop (可能是 $row['metavalue'])列是否为空。我还没有深入研究 WordPress 来了解确切的列名称,但从您所提供的内容来看,这可能就是您正在寻找的内容。 (顺便说一句,您也可以更轻松地为“FROM $wpdb->posts”部分添加别名。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文