404 error on all other pages except page one in WordPress pagination on category
-
I am fetching YouTube feed from api in WordPress and creating posts from that data, assigning it “videos” category. I am facing a problem in pagination in category pages only for this category page when, basically it creates the pagination links if more posts are created but giving 404 error on all the other pages except first one. I am not using custom post type but the default “post” type to create posts through my code. When I remove, all the created file, the pagination on this category works fine. I have also tried to create the posts with REST API, but facing the same issue. Thanks in advance for help.
$data = file_get_contents($url); if(!empty($data)){ $data = json_decode($data); foreach ($data->items as $item) { $title = $item->snippet->title; $description = $item->snippet->description; $video = $item->id->videoId; $thumbnail = $item->snippet->thumbnails->default->url; $content = '<p style="text-align:center">https://www.youtube.com/watch?v='.$video.'</p>'; // Prepare post data $post_data = array( 'ID' => 0, 'post_author' => $user->ID, 'post_content' => $content, 'post_content_filtered' => '', 'post_title' => $title, 'post_excerpt' => $description, 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_password' => '', 'post_name' => sanitize_title($title), 'to_ping' => '', 'pinged' => '', 'post_parent' => 0, 'menu_order' => 0, 'post_mime_type' => '', 'guid' => '', 'import_id' => 0, 'post_category' => array( $category_id), 'meta_input' => array( 'primary_category' => $category_id ), 'page_template' => 'category.php' ); $post_id = wp_insert_post($post_data); } }
I have already done the following:
- Updating the permalink settings
- Updating the .htacess file
- Made changes to the $wp_query using pre_get_posts
- The topic ‘404 error on all other pages except page one in WordPress pagination on category’ is closed to new replies.