Site icon Hip-Hop Website Design and Development

Set a number of Publish Phrases in similar Taxonomy

I am having a tough time making an attempt to determine this downside. I’ve checked out numerous StackExchange threads however nothing appears to work.

Lengthy story quick. I’ve a customized desk that updates every single day which shops information concerning the Every day, Weekly, and Month-to-month reputation of publish merchandise.

Right here is an extract of the desk:

id date rank_d rank_w rank_m
1 2021-09-14 sku-1
2 2021-09-14 sku-2
.. .. .. .. ..
17 2021-09-01 sku-2 sku-27 sku-3
18 2021-09-01 sku-11 sku-1 sku-4

rank_d, rank_w, rank_m symbolize the SKU of the product.
Whereas each day rating is filtered by "today" date the month-to-month/weekly in style product is saved on the finish of the desk (i.e. at rows 17/18).

I must replace publish phrases for every publish product related to the SKU within the desk with the intention to filter it inside the entrance finish. I can add 1 time period however I want help so as to add extra phrases to the identical SKU. Particularly, at 2021-09-14, I anticipate this final result:

Right here beneath the code:

add_action('init', 'update_post_terms_gtrends_w_m');

perform update_post_terms_gtrends_w_m() {
    international $wpdb;
    
    $args = array(
        'posts_per_page' => -1,
        'post_type' => 'product',
        'suppress_filters' => true,
        'meta_key' => '_sku'
    );
    
    $immediately = date("Y-m-d", strtotime( '-1 days' )); 

    $posts_array = get_posts( $args );
    
    $customTable_2 = $wpdb->prefix.'gtrends_top_w_m';
    
    foreach($posts_array as $publish) {      
        $post_id = $post->ID;
        $post_sku = get_post_meta($post_id,'_sku',true);

// Get outcomes from customized tables   
        $result_top_d = $wpdb->get_var( "SELECT rank_d FROM $customTable_2  WHERE rank_d = '$post_sku'  and date = '$today' ");        
        $result_top_w = $wpdb->get_var( "SELECT rank_w FROM $customTable_2  WHERE rank_w = '$post_sku' ");  
        $result_top_m = $wpdb->get_var( "SELECT rank_m FROM $customTable_2  WHERE rank_m = '$post_sku' ");
            
// Assign post-terms                    
        if ($result_top_d != NULL){
            wp_set_post_terms( $post_id, array(2119), 'in style', true );            
            }
        
        else if ($result_top_w != NULL ){
            wp_set_post_terms( $post_id, array(2120), 'in style', true );            
            }
        
        else if ($result_top_m != NULL ){
            wp_set_post_terms( $post_id, array(2118), 'in style', true );            
            }
    
        else{
            wp_remove_object_terms($post_id, array(2118,2119,2120), 'in style' );
        }               
    }
}

Thanks upfront