Ok, I found the solution for this specific case, since it’s a template for the articles.
On the admin settings, define the custom page as the page for the articles. And using the code I posted in the question, everything works just fine.
Now, if you are using a page for the homepage, another for the articles, and you have another custom page that needs pagination, this solution won’t work.
If anyone knows how to fix that, it would be good to leave the info here.
Related Posts:
- Define page template in wp_insert_post
- Add custom template page programmatically
- Define custom Page Template without its own .php file
- paginate_links() don’t properly work in search.php?
- How to paginate the get_users function?
- Pagination adding page-numbers dots when using ‘mid_size’ => 0
- Filter the query ONLY for the search results page
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How to style current page number (wp_link_pages)?
- Custom page template how to check is_page from functions.php?
- Run Product Filter Javascript On Page Template
- Customize “the_posts_pagination” and put list instead div
- Programmatically set page template based on page ID
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Adjust which tempalte a page uses with a function?
- How to specify which Gutenberg blocks are available in the editor for a page template
- how to change link of some wordpress pages
- Find first image on paginated post for Pinterest
- Post Pagination Showing Same Posts Every Page
- Filtering posts by category name based on page’s slug
- Generating rel=prev and rel=next only on wordpress categories
- is_account_page() change to page slug
- How to enable template page only for a post id page
- Shortcode pagination not advancing
- Activate small php condition at footer over page template
- Get_template_part inside a folder
- get_next_posts_link not working without parameter max_num_pages
- Pagination in relation to archive.php
- paginate_links() don’t properly work in search.php?
- Pass parameter to hooked function using custom page template
- different style sheet for just one page template
- the_posts_pagination() function returns missing page numbering on some blog pages
- Custom Query Not Paginating
- Where to call my pagination function?
- Remove ‘page-numbers’ class from prev and next tags
- Modifying the_posts_pagination from within functions.php instead of template files
- Page Template Won’t Load Correct CSS File
- Unable to Change “Pages:” Before WP_LINK_PAGES
- Function to check if custom page is used by page?
- Unable to use get_page_by_title() more than once per page?
- How to Override Page Template if URL matches query?
- Probleme shortcode with list author
- How Can I Create a Friendly Slug for a Dynamic Page?
- Enqueue script if not page template
- How do I make a custom “Read More Blogs” button for my blog page
- I want to customize the_posts_navigation function by replacing prev and next with images
- Shortcode with pagination advancing multiple queries
- Edit meta fields from within template
- Pagination not working on my archive page for a custom post type
- Display page number on custom page title function
- Sending Messages Back to the Template After Processing?
- is_page_template wont allow me to enqueue scripts
- WordPress not showing pagination links
- Pagination in Search result
- How to use different jquery function of idangero swiper dependant on page template?
- Adding pagination to custom WordPress function
- Modifying Page-Links format
- WordPress is adding pagination for all pages not only for blog page, How to remove pagination for all pages except blog/posts page?
- Insert image between X number of posts but on specific paginated pages?
- Logout redirect via page template without confirmation?
- Template Redirect Function Only Working When Logged In
- Ajax call always returns 0
- Where and how to put inline js in pages
- Hourly Routine Not Firing ( wp_schedule_event() )
- echo or print_r in an admin function
- Overriding methods in a child theme
- WP disobeys disabling of the posts revision feature
- Adding widget to dashboard with wp_dashboard_setup not working
- Register and load scripts
- Having a Function Inside of the Loop
- About cron delete user with meta_key
- Unable to login using username
- How to change the order of Jquery in the footer of my theme?
- media resize/crop possibilities?
- adding custom script to functions file
- edit formatting.php in a theme so it wont get overwritten
- add_action template_redirect not working for home page
- Way to store featured image width and height in two separate variables?
- Insert template-part inside the content
- Add unique id to Preview URL
- Numbering lines of code with the tag?
- Latest Foursquare Checkin function
- How to use parent theme functions in child theme functions.php file?
- How to change a specific admin label
- Pagination Not Working (pages duplicating content)
- How to add extra value to permalink
- Bulk updating a group of WordPress Pages every 10 minutes
- remove_filter function to unhook twentysixteen parent theme function
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- ACF Filter return value
- Changing the color of post title [closed]
- Create html from function
- wp_list_pages change of children and anchor of parent
- Admin Panel errors because of functions.php
- WordPress not performing direct update
- Using Output from one Function and calling it into another
- How to add a class and title attribute to the link generated by next/previous post
- “Headers already sent” while trying to add a CSS file to my login page?
- Notice: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ in ….functions.php on line 73
- Is storing in a variable the result of a fonction a most powerful way to code an if structures in WordPress?