在wordpress中选择查询 [英] select query in wordpress

查看:40
本文介绍了在wordpress中选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在2个小时之前完成此操作. 我在数据库中有自定义字段,我想通过meta键或meta值获取post_id. 我就是这样

I am trying to do this by 2 hours. I have custom fields in database and I want to get post_id by the meta keys or meta values. I am doing like this

$post_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = 'mfn-post-link1' AND meta_value = '". $from ."')");
print_r($post_id); // giving only 140

这工作正常,但这只给出了一个post_id,我希望所有可能的post_id与meta_value匹配. 例如 : 我在数据库中有3个帖子140,141,142.但是通过此查询,我只能得到140. 任何想法如何通过此查询或通过比较meta_fields以任何其他方式获取所有可能的post_id ...

this is working fine, but this is giving only one post_id and I want all possible post_id matched by meta_value. for example : I have three post 140,141,142, in database. But by this query I am only getting 140. Any Idea how to get all possible post_id by this query or any other way by comparing meta_fields...

谢谢

推荐答案

$post_id = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = 'mfn-post-link1' AND meta_value = '". $from ."')");
print_r($post_id); /

这篇关于在wordpress中选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆