WordPress: community-new/page/2/ not found

[ad_1]

So basically, I created a custom post with Advanced Custom Fields for WordPress that includes pagination. The pagination renders even and adequately shows the pagination button, but when I navigate to the second page, it goes to `/community-news/page/2/`, which leads to a `404 ` error. The main page is `/community-news`. I have had added the `custom_disable_redirect_canonical` function in my `function.php` as required but still it doesn’t work. I also changed the permalink to Custom structure `/community-news/page/%pagename%/` but nothing

I am using the shortcode to add the PHP function to my page and the function is as follows

“`

function display_all_news() {
// Query all news posts
$args = array(
‘post_type’ => ‘community-news’,
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘posts_per_page’ => 5, // Adjust as needed
‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1
);

$query = new WP_Query($args);
$output = ”;

// Check if there are any news posts exists
if ($query->have_posts()) {

// Start card container
$output .= ‘<div class=”card-container”>’;

while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
$news_title = get_the_title();
$news_featured_image = get_the_post_thumbnail_url($post_id, ‘large’);
$news_description = get_the_excerpt();
$news_createdAt = get_the_date(‘F j, Y’, $post_id);
$author_name = get_the_author();
$news_link = get_field(‘post_link’, $post_id);

// Build HTML output for each community post
$output .= ‘<div class=”card”>’;

$output .= ‘<figure class=”card-image”>’;
if ($news_featured_image) {
$output .= ‘<img src=”‘ . esc_url($news_featured_image) . ‘” alt=”‘ . esc_attr($news_title) . ‘” />’;
}
$output .= ‘</figure>’;
$output .= ‘<div class=”card-content”>’;
$output .= ‘<span class=”author”>Author: ‘ . $author_name . ‘</span>’;
$output .= ‘<span class=”date”>Posted on: ‘ . $news_createdAt . ‘</span>’;
$output .= ‘<h2>’ . esc_html($news_title) . ‘</h2>’;
$output .= ‘<p>’ . esc_html(shorten_post($news_description)) . ‘</p>’;

//button
$output .= ‘<div class=”btn-container”>’;
// button tag
$output .= ‘<a class=”btn” href=”‘ . get_permalink() . ‘” class=”see-more”>See More</a>’;
$output .= ‘</div>’;

$output .= ‘</div>’;

$output .= ‘</div>’;

}

$output .= ‘</div>’;

// Reset post data
wp_reset_postdata();

// Pagination Links
$output .= ‘<div class=”pagination-links”>’;
$output .= paginate_links( array(
‘total’ => $query->max_num_pages,
‘current’ => $paged,
‘prev_text’ => __( ‘Previous Page’, ‘textdomain’ ),
‘next_text’ => __( ‘Next Page’, ‘textdomain’ ),
) );
$output .= ‘</div>’;

return $output;
}

return ‘No News posts found.’;
}

add_shortcode(‘all_news’, ‘display_all_news’);
“`

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer