Couple of issues here
-
You custom query should be inside your conditional statement
-
Use
get_posts
which only returns the$posts
property -
wp_reset_query()
is used withquery_posts
which you must never ever use -
No need to the
$post
global
Your code should look something like this
add_action( 'pre_get_posts', 'cdbz_modify_main_query' );
function cdbz_modify_main_query( $query )
{
if ( !is_admin()
&& $query->is_home()
&& $query->is_main_query()
) {
$fArgs = array(
'category_name' => 'prima-pagina',
'posts_per_page' => 1,
'ignore_sticky_posts' => 1,
'fields' => 'ids'
);
$featured = get_posts( $fArgs );
if ( $featured )
$query->set( 'post__not_in', $featured );
}
}
EDIT
From comments, you need to know why the custom query needs to be inside your conditional statement. The reason for this is, you would only want to run the custom query when we are on the home page and only for the main query. As your code stands, you are running the custom query on every page load and for all custom queries, and even on the back end, regardless. This is unnecessary and a waste of resources.
I hope that makes sense