在Wordpress中连续查询

时间:2015-08-20 15:23:53

标签: arrays wordpress meta-key

我正在尝试从wp_postmeta表中显示找到的post_id的一些meta_values和meta_keys,以及从wp_posts表中显示此ID的post_title。首先,我必须从给定的meta_key和meta_value中找到post_id(可能不止一个)。我必须检索与表中的post_ids相关的其他meta_values和meta_keys。我已设法使用以下代码检索post_id;

 public func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

        if let textField = textField as? UITextField {

            if (range.length + range.location > textField.text!.characters.count) {
                return false;
            }

            let newLength = textField.text!.characters.count + string.characters.count - range.length;
            switch(textField.tag) { //In case you want to handle multiple textfields
                case Constants.TAG1:
                    return newLength <= 20;
                case Constants.TAG2:
                    return newLength <= 30;
                default:
                    return newLength <= 15;
            }
        }
        return true;
    }

它表明了;
3873
3797
例如。然后我在foreach中添加以下代码;

$meta_key = "wcum_users_id"; 
$meta_value = "2";

$posts = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = '$meta_key' AND meta_value = '$meta_value' ");
foreach ( $posts as $post ){

$id = $post->post_id;

echo $id;

结果;
3783
trl2000
hgld2015
3797
trl2000
hgld2015

但我需要这样的结构;

标题| meta_key1 | meta_key2 | meta_key3
$ post_id1 | meta_value11 | meta_value12 | meta_value13
$ post_id2 | meta_value21 | meta_value22 | meta_value23

有可能吗?

0 个答案:

没有答案