【发布时间】:2017-06-20 13:30:09
【问题描述】:
您好,我需要使用 like 运算符按类别 id 和帖子标题获取帖子类型的结果。
例如
Category name : Sports
Post name : Basketball , hockey , volley ball
从下面的查询中,我得到帖子名称及其 ID,并将它们传递给 get post 查询,但查询返回该类别内的所有帖子
假设我在该类别中搜索排球,我得到所有结果,我只需要输出中的排球。
在下面查看我的代码
$mypostids_title = $wpdb->get_col("select ID from $wpdb->posts where post_title like '%$title%'");
$args_sby= array(
'post_type' => 'campaign',
'post_status' => 'publish',
'posts_per_page' => -1,
'post__in' => $mypostids_title,
'tax_query' => array(
array(
'taxonomy' => 'campaign_category',
'field' => 'term_id',
'terms' => $_GET['c'],
'operator' => 'AND',
)
),
);
$posts = get_posts($args_sby);
我从上面的 select 查询中获取了 post id 数组,并将它们传递到 get post 查询参数中,我只得到分类的结果,但我需要通过分类和 post id 获取结果,请告诉我如何解决这个问题。 提前致谢。
【问题讨论】:
-
在 $_GET['c'] 变量中你得到了什么?术语 ID 或术语 slug ?
标签: php wordpress custom-post-type