Site icon Hip-Hop Website Design and Development

wp_term_relationships not updating when using update_post_meta

A theme I am using lists cars using the STM Motors theme. Basically a car listing site.

The cars are listed under a post type of "listings".

There are various options (transmission, fuel type etc..)

I have a cron calling a remote json feed to add the cars.

After import the car listing page looks fine, however in other pages all the options are not showing (the listings page).

If I edit the car page, and update (without making changes) it works correctly across the whole site.

Dumping the DB before updating and after shows the wp_term_relationships are only added after I update using the back end.

Stuck as I can’t see any issue with what I am doing. Example code below

$transmission = "Automatic";
if (!term_exists($transmission, 'transmission')) {
    wp_insert_term($transmission, 'transmission');
}

Some of the types of transmission do not exist, hence adding them as above.

$post_data = array(
    'post_title'    => wp_strip_all_tags($postname),
    'post_content'  => $content,
    'post_name' => wp_strip_all_tags($postname . " " . $json['car_id']),
    'post_type'     => 'listings',
    'post_author'   => POST_AUTH_ID,
    'post_category' => array(),
    'page_template' => ''
);
$new_post_id = wp_insert_post($post_data, $error_obj);

update_post_meta($new_post_id, 'transmission', strtolower(sanitize_title($transmission)));

There are various other options here as above, some default/blank, others from the feed

I also update the HTML and then save it here

$post = get_post($new_post_id);
$post->post_status = "publish";
wp_update_post($post);