php 在wordpress中选择查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19493075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
select query in wordpress
提问by Dinesh
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
我试图在 2 小时内做到这一点。我在数据库中有自定义字段,我想通过元键或元值获取 post_id。我这样做
$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
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,我希望所有可能的 post_id 与 meta_value 匹配。例如:我在数据库中有三个帖子 140,141,142。但是通过这个查询我只得到 140。任何想法如何通过这个查询或任何其他方式通过比较 meta_fields 来获取所有可能的 post_id ...
Thanks
谢谢
回答by codepixlabs
$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); /
回答by LUCKY
$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);
for more information ... http://codex.wordpress.org/Class_Reference/wpdb