query wp – WP_query with pagination gives a 404 after page 1

So I could not display a custom pagination on a custom wp_query index.php page and then I found this answer wordpress.stackexchange.com/questions/160175/pagination-on-a-wp-query-not-showing-navigation-links and then he managed to show the personalized pagination. Unfortunately, even though it is shown, the pagination is broken when I click on page 2 (or another number) and it gives an error 404. I tried it $ paged = (get_query_var (& # 39; paged & # 39;))? get_query_var (& # 39; paged & # 39;): 1; Y $ paged = (get_query_var (& # 39; paged & # 39;))? get_query_var (& # 39; paged & # 39;): 1; without result I have seen many other questions with answers, but everything I could try does not work. I'm sure I'm missing something … Here where I'm lying right now:

Paging function in functions.php

pressPagination function ($ pages = & # 39; & # 39 ;, $ range = 2)
{
$ global paged
$ showitems = ($ range * 2) +1;

if (empty ($ paged)) $ paged = 1;
yes ($ pages == & # 39; & # 39;)
{
global $ wp_query;
$ pages = $ wp_query-> max_num_pages;
yes (! $ pages)
{
$ pages = 1;
}
}

yes (1! = $ pages)
{
echo "";
}

}

custom WP_query in index.php

    array (& # 39; post & # 39 ;, & # 39; tribe_events & # 39;),
& # 39; posts_per_page & # 39; => 10,
& # 39; orderby & # 39; => & # 39; title & # 39 ;,
& # 39; order & # 39; => & # 39; ASC & # 39 ;,
& # 39; paged & # 39; => $ paged,
);

// the query
$ actualites_query = new WP_Query ($ actualites_args);

global $ wp_query;
// Put query object by default in a temporary variable
$ tmp_query = $ wp_query;
// Now clean it completely
$ wp_query = null;
// Re-populate the global with our personalized query
$ wp_query = $ actualites_query;
?>

have_posts ()):?>




have_posts ()): $ actualites_query-> the_post (); ?>










Thank you 🙂