0

我有这个自定义查询,我需要这样做来检查 post_metadata 值和分类术语。我正在使用从 Wordpress 的 codex 修改的代码,但它始终返回零结果。我犯了一个错误吗?(更新:显示它首先被加载到变量中的位置)

global $wpdb;

$querystr = "
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE $wpdb->terms.name = '" . $service . "'
    AND $wpdb->term_taxonomy.taxonomy = 'Services'
    AND $wpdb->postmeta.meta_value = '" . $county . "'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    AND $wpdb->postmeta.meta_key = 'order'
    ORDER BY $wpdb->postmeta.meta_value ASC";

$pageposts = $wpdb->get_results($querystr, OBJECT);
4

1 回答 1

0

我建议记录执行的实际字符串(将此选择保存到变量并记录变量,然后将变量传递给 wpdb 查询)。获得 sql 后,您可以更轻松地对其进行故障排除(或在此处发布以获得进一步帮助)。

于 2013-09-04T20:15:37.457 回答