为了获取帖子,我有一个包含多个连接的查询,通过WP\\u查询使用起来非常复杂。
SELECT p.post_name, t.name as sname, t2.name as cname FROM wpw0_posts AS p
INNER JOIN wpw0_term_relationships AS tr ON p.ID = tr.object_id
INNER JOIN wpw0_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id && tt.taxonomy = \'storylines\'
INNER JOIN wpw0_terms AS t ON t.term_id = tt.term_id
INNER JOIN wpw0_term_relationships AS tr2 ON p.ID = tr2.object_id
INNER JOIN wpw0_term_taxonomy AS tt2 ON tr2.term_taxonomy_id = tt2.term_taxonomy_id && tt2.taxonomy = \'company\'
INNER JOIN wpw0_terms AS t2 ON t2.term_id = tt2.term_id
WHERE p.post_status = \'publish\' AND p.post_type = \'post\'
ORDER BY p.post_date DESC
因此,我使用$wpdb object和get\\u results()方法获取帖子,但原始模板有许多WP\\u查询方法,如get\\u the\\u post\\u thumbnail\\u url()、get\\u the\\u category()等。因此,为了使用相同的模板,我想从
$wpdb->get_results($sql);
至new WP_Query($args);
如何转换对象或转换查询?