I am kinda a newbie at Wordpress. I've looked a lot on StackOverflow for a solution for this problem but none worked for me. I'm using Timber and ACF.
Here's the situation: I've made 4 custom post_type ( News, Products, Services and Places ). I've created a custom page for the news. (page-news.twig )
In my page.php
file I've added a custom query like this:
global $paged;
if (!isset($paged) || !$paged) {
$paged = 1;
}
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$args = array(
'post_type' => 'news',
'posts_per_page' => 3,
'paged' => $paged,
'page' => $paged
);
$context['news'] = new Timber\PostQuery($args);
So I've set a maximum of posts for page, which is 3, and In my .twig file:
{% for single_news in news %}
{% include['news.twig', single_news] %}
{% endfor %}
{% if news.pagination.prev %}
<a href="{{news.pagination.prev.link}}" class="prev {{ news.pagination.prev.link|length ? '' : 'invisible'}}">Prev</a>
{% endif %}
{% if news.pagination.next %}
<a href="{{ news.pagination.next.link}}" class="next {{ news.pagination.next.link|length ? '' : 'invisible'}}">Next</a>
{% endif %}
When I go to the news page, there are 3 posts per page ( correct ) and it displays me the Next
anchor which is correct.
The problem is that the link brings me to /news/page/2
that doesn't exists and gives me 404 error. I've tried many solutions like the pre_get_posts and none worked for me.