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