php - Data not stored in Wordpress Database
Get the solution ↓↓↓I have been trying to troubleshoot a plugin that fetches data from an API and stores the data in a mysql database. The problem is that the plugin stopped storing the data a while ago. I deleted some data to free up some space, checked any and all error messages, without luck. The code that stores content in the data base is:
$new_part_in_wpdb = array(
'post_title' => $truck_part_title_without_sku, // The cleaned title
'post_content' => $parts_result['description'], // The text content
'post_name' => $truck_part_slug, // The name (slug)
'post_status' => 'publish', // Make it live
'post_type' => 'part', // Define the CPT
'post_author' => 1 // Set an author ID
);
$post_id = wp_insert_post( $new_part_in_wpdb );
update_post_meta( $post_id, 'vendor_sku', $parts_result['vendor_sku'] );
update_post_meta( $post_id, 'part_details_json', json_encode( $part_details ) );
wp_set_object_terms( $post_id, (int)$truck_part_tax_id, 'part_type', false );
if (is_wp_error( $post_id )) {
$errors = $post_id->get_error_messages();
foreach ($errors as $error) {
echo $error;
}
}
endif;
// Reset Post Data
wp_reset_postdata();
The API fetch is fine and anything above the code seems to work properly. There are 18000+ posts in the database, everything in the database gets displayed properly. The cron job is set to hourly, but nothing gets saved. I am not sure if a recent WP version had anything to do with it. Any pointers would be greatly appreciated.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function store() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.