我正在制作一个页面模板,该模板应显示具有与页面标题匹配的元值的自定义帖子类型。元价值是通过Advanced Custom Field 单选按钮,但查询没有考虑meta,而是显示所有帖子。我查过了$name
存储正确的字符串,帖子的值正确program
钥匙
以下是查询代码:
$name = get_the_title(get_the_ID());
$args = array(
\'post_type\' => \'project\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
\'key\' => \'program\',
\'value\' => $name,
\'compare\' => \'LIKE\'
)
);
$projects_q = new WP_Query($args);
我甚至尝试将“value”值包装在
""
并更改
$name
小写,但结果相同。
$name = strtolower(get_the_title(get_the_ID()));
$args = array(
\'post_type\' => \'project\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
\'key\' => \'program\',
\'value\' => \'"\' . $name . \'"\',
\'compare\' => \'LIKE\'
)
);
$projects_q = new WP_Query($args);
有没有什么特殊的方法可以用单选按钮查询帖子?
SO网友:Bojana Šekeljić
我试过用普通的meta_key
- meta_value
配对,按它应该的方式工作。。。
$name = get_the_title(get_the_ID());
$args = array(
\'post_type\' => \'project\',
\'posts_per_page\' => -1,
\'meta_key\' => \'program\',
\'meta_value\' => $name,
);
$projects_q = new WP_Query($args);