Reputation: 1
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. 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), // Set the category IDs
'tags_input' => '',
'tax_input' => array( $category_id),
'meta_input' => array(
'primary_category' => 'videos'
),
'page_template' => 'category.php'
);
// Insert the post into the database
$post_id = wp_insert_post($post_data);
}
}
Upvotes: 0
Views: 56