admin管理员组文章数量:1129001
I used the guide HERE from acf themselves, but for some reason whenever I attempt to query anything at all in the url I get the "There has been a critical error on this website" error.
$GLOBALS['my_query_filters'] = array(
'field_1' => 'bedrooms',
);
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts( $query ) {
// bail early if is in admin
if( is_admin() ) return;
// get meta query
$meta_query = $query->get('meta_query');
// loop over filters
foreach( $GLOBALS['my_query_filters'] as $param => $key ) {
// continue if not found in url
if( !empty($_GET[ $param ]) ) {
$value = explode(',', $_GET[ $param ]);
// append meta query
$meta_query[] = array(
'key' => $key,
'value' => $value,
'compare' => 'IN',
);
}
}
// update meta query
$query->set('meta_query', $meta_query);
return;
}
Here is the code I used, almost verbatim what is used in the tutorial and yet I have had no success. I've tried on two completely separate websites, one using a theme created by the Create Block Theme plugin and the site editor and the other using a custom theme fully coded out. In the latter one it uses a standard WP_Query loop to output all the posts from the particular post type.
本文标签: How do I add a filter to my custom post type archive page
版权声明:本文标题:How do I add a filter to my custom post type archive page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736729566a1949917.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论