Your code is quite messy which makes debugging hard, so I cleaned up your code a bit.
The posts_results
filter accepts two parameters, one being the posts results array, and the second one is the current WP_Query
instance. So you can pass the second argument and then test for your conditions.
I haven’t tested your code, just cleaned it up and added the second parameter. The following should work: (REQUIRES PHP 5.4+)
add_filter( 'posts_results', 'insert_post_wpse_96347', 10, 2 );
function insert_post_wpse_96347( $posts, \WP_Query $q )
{
remove_filter( current_filter(), __FUNCTION__ );
if ( $q->is_main_query()
&& $q->is_home() &&
0 == get_query_var( 'paged' )
) {
$args = [
'meta_key' => 'Caja',
'meta_value' => ['UNO','DOS'],
'post__not_in' => get_option( "sticky_posts" ),
'posts_per_page' => '2',
'suppress_filters' =>true
];
$p2insert = new WP_Query($args);
$insert_at = 0;
if ( !empty( $p2insert->posts ) ) {
array_splice( $posts, $insert_at, 0, $p2insert->posts );
}
}
return $posts;
}