I have a page in ‘Pages‘ called ‘News‘. This page has a template containing my paged custom WP_Query
.
Here’s the code:
<?php
$paged = 1;
if (get_query_var('paged')) {
$paged = get_query_var('paged');
} elseif (get_query_var('page')) {
$paged = get_query_var('page');
}
$arguments = array (
'posts_per_page' => 3,
'post_type' => 'fltnews',
'paged' => $paged,
'meta_key' => 'publish_date',
'orderby' => 'meta_value',
'order' => 'DESC'
);
$custom_wp_query = new WP_Query($arguments);
$temp_wp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_wp_query;
echo "<ul class="content-list">";
if ($custom_wp_query->have_posts()) :
while ($custom_wp_query->have_posts()) : $custom_wp_query->the_post();
echo "<li class="content-list-item">";
$podsForNewsItem = pods('fltnews', $post->ID);
$podsImage = pods_image ( $podsForNewsItem->display( 'thumbnail_picture'), 'full');
if ($podsImage != ""){
$podsImage = "<div class="content-list-thumbnail-picture">" . $podsImage . "</div>";
}
printf("<a href="https://wordpress.stackexchange.com/questions/222367/%s" class="item-container">%s
<div class="content-list-body">
<div class="content-list-publisher">
<div class="date-block"><span class="date">%s</span></div>
</div>
<div class="content-list-title">%s</div>
<div class="content-list-text">%s</div>
<div class="content-list-link">Les mer</div>
</div>
</a>",
esc_url(get_permalink($post->ID)),
$podsImage,
getDateAsNorwegian($podsForNewsItem->field('publish_date')),
$post->post_title,
$post->post_excerpt);
echo "</li>";
endwhile;
wp_reset_postdata();
previous_posts_link('Nyere »');
next_posts_link('« Eldre nyheter', $custom_wp_query->max_num_pages);
$wp_query = NULL;
$wp_query = $temp_wp_query;
endif;
echo "</ul>";
?>
I’ve looked at the following questions and answers:
- How to fix pagination for custom loops?
- Pagination gives 404 error
It seems like everyone always fixes the 404 problem when adding the ‘paged‘ key and value to the WP_Query
. However, this doesn’t work for me.
The page ‘News‘ is at the following URL: /news.
The next_posts_link
gives the following link: /news/page/2.
This is the one giving me the 404.
My Permalink Settings is as follows: Day and name.
I don’t understand why I’m getting the 404.