admin管理员组文章数量:1277902
I have 3 custom post types, which are related to each other. Projects, Positions and Feedbacks. 1 Project has many Positions and 1 Position has many Feedbacks.
Relations are defined with meta values. Feedbacks post has a meta value, where the value points to position post id, and Positions post has a meta value, where the value points to project post id.
I want to create a custom filter in Feedback admin list, where rows are filtered by project.
It would be nice to do it with a 'parse_query' filter, since I already have some filters attached to it.
How to achieve this?
I have 3 custom post types, which are related to each other. Projects, Positions and Feedbacks. 1 Project has many Positions and 1 Position has many Feedbacks.
Relations are defined with meta values. Feedbacks post has a meta value, where the value points to position post id, and Positions post has a meta value, where the value points to project post id.
I want to create a custom filter in Feedback admin list, where rows are filtered by project.
It would be nice to do it with a 'parse_query' filter, since I already have some filters attached to it.
How to achieve this?
Share Improve this question edited Aug 18, 2021 at 14:08 Hannes Härm asked Aug 18, 2021 at 10:28 Hannes HärmHannes Härm 12 bronze badges 2- What have you tried so far? – Mat Commented Aug 20, 2021 at 15:00
- I have found a semi solution. Ill post it as one of answers – Hannes Härm Commented Aug 20, 2021 at 23:14
1 Answer
Reset to default 0One solution may be to get all position ids, where project id matches and compare them with the 'OR' comparer.
$position_ids = get_positions_in_project($project_id);
foreach ($position_ids as $id) {
$meta_query[] = array(
'key' => 'feedback_position_relation',
'value' => $id,
'compare' => '=',
);
}
$meta_query['relation'] = 'OR';
$query->set('meta_query', $meta_query)
But the problem with this is, that meta query does not accept complex parameters. I want a feedback where the position id is 1 and project id is 2. The relation will always be 'OR'.
In a simple problem this solution should give the answer. For my sake this solution does not work, since i want to give the user the ability to filter other parameters too.
I have searched for 'in array' meta_query, but this seems to be not supported.
UPDATE
With wordpress 5.8.1 (I have no idea if earlier versions work), the IN Array comparison works.
if ($_GET['project'] != 'all') {
$project_id = $_GET['project'];
$positions = get_position_ids_by_project($project_id);
$meta_query[] = array(
'key' => 'summary_summary_position',
'value' => $positions,
'compare' => 'IN',
);
}
$query->set('meta_query', $meta_query)
本文标签:
版权声明:本文标题:Filter custom post type admin list by custom meta column, where the column is another custom posts meta value 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741303177a2371216.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论