在我的自定义搜索表单中,我当前在WP查询中使用以下类型的$args:
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => $postsPerPage,
\'offset\' => $postOffset,
\'category\' => 42,
\'s\' => $name, //value of my searched term
\'orderby\' => \'date\',
\'order\' => \'DESC\',
);
我想按“标题”或“标签”搜索帖子。
我已尝试使用此代码:
$query_args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'order\' => \'ASC\',
\'orderby\' => \'none\',
\'posts_per_page\' => \'100\',
\'offset\' => \'2\',
\'page\' => \'2\',
\'tax_query\' => array(
\'0\' => array(
\'taxonomy\' => \'post_tag\',
\'field\' => \'name\',
\'terms\' => array(\'test\'),
\'operator\' => \'IN\',
),
\'relation\' => \'OR\',
),
\'meta_query\' => array(
\'0\' => array(
\'key\' => \'post_title\',
\'value\' => \'test\',
\'compare\' => \'LIKE\',
),
\'relation\' => \'OR\',
),
但结果是空的。
谢谢
SO网友:Dino Morrison
尝试删除tax\\u查询和meta\\u查询数组中的“0”键。
$query_args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'order\' => \'ASC\',
\'orderby\' => \'none\',
\'posts_per_page\' => \'100\',
\'offset\' => \'2\',
\'page\' => \'2\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'post_tag\',
\'field\' => \'name\',
\'terms\' => array(\'test\'),
\'operator\' => \'IN\',
),
\'relation\' => \'OR\',
),
\'meta_query\' => array(
array(
\'key\' => \'post_title\',
\'value\' => \'test\',
\'compare\' => \'LIKE\',
),
\'relation\' => \'OR\',
),
在您的第一组参数中
\'category\' => 42
, 但这应该是
\'cat\' => 42
,