Karun’s answer made me look more into the posts_where
filter to find a better solution to hook into the WP_Query. After a bit more google searching I found this page that did it in a better way.
Using that method I finally got it to work like this:
add_filter('posts_where', function ($where, $query)
{
global $wpdb;
$label = $query->query['query_label'] ?? '';
if ($label === 'ignore_zero_query')
{
$where .= " AND {$wpdb->prefix}posts.menu_order > 0 ";
}
if ($label === 'only_zero_query')
{
$where .= " AND {$wpdb->prefix}posts.menu_order <= 0 ";
}
return $where;
}, 10, 2);
And I now get the posts this way instead:
$args = array(
'posts_per_page' => -1,
'query_label' => 'ignore_zero_query',
);
$posts_query = new WP_Query();
$posts = $posts_query->query($args);