Query in do loop

Why is the following code not working? :

Do[gm = 200*N[Pi];  s1 = k^2 + (d - ((g1^2)*points[i, 2, 1]/wm))^2 + 2*k*gm + wm^2;  s2 = (k^2 + (d - ((g1^2)*points[i, 2, 1]/wm))^2)*gm + 2*k*wm^2;  s3 = (k^2 + (d - ((g1^2)*points[i, 2, 1]/wm))^2)*(wm^2) - (d - (g1^2*         points[i, 2, 1]/wm))*wm*(g1^2)*(2 points[i, 2, 1]);  If[(2 k + gm) s1 > s2, Print[True], Print[False]];  If[s1*s2 (2 k + gm) > s2^2 + (2 k + gm)^2*(s3), Print[True],    Print[False]];  If[s1 > 0, Print[True], Print[False]];  If[s2 > 0, Print[True], Print[False]];  If[s3 > 0, Print[True], Print[False]], {i, 11}] 

Please suggest ways to tweak this or an alternative method.

How can I properly loop through an array gotten from my wordpress database and display it to my site

I am trying to display some posts information from my database on my live site. I have done the query correctly because I can view the items on the live site. But I need to take three items to display. The post title, the post content which houses the images, and the post id which links to the posts. I seem to have written it correctly but it does not do anything.

This is the code

<?php      global $  wpdb;                    $  results = $  wpdb->get_results( "SELECT * FROM $  wpdb->posts WHERE `post_type`='post' AND `post_status` = 'publish' LIMIT    20" );    foreach ($  results) {       echo "<div class="card">             <div class="img">              <img src="{post_content}" alt="">             </div>             <div class="info">                <h5>{post_title}</h5>             </div>           </div>";   }    //echo "<pre>";print_r($  results);echo"</pre>";                      ?>  

I am quite new to wordpress and PHP in general.

Time complexity of pairs in array double loop

I know, that the following is: O(n^2),

int count = 0; for(int i = 0; i<array.length(); i++) {    for(int j = i+1; j<array.length(); j++) {        if(array[i] == array[j]) {            count = count + 1;        }    } } 

But, should something like count = count + 1; be taken into account? For predicting or making up a complex time equation, or using sum notation,

n + n-1 + n-2 + n-3 + (…) + 1 

issue with if/elseif in_array inside foreach loop display only one post

I try to attribute a specific background-color to each post if one of categories of post corresponding to one category. My function works but is restricted to display only one post in result. If I delete this function, all post are displayed.

More informations : On my page I have buttons to filter posts by category. if I click on once I display all post for this category. But each post contains several categories. I have selected some categories to attribute a background colors for each posts, but theses categories are different of the filters buttons.

WordPress display this error "a critical error has occurred on your site, Learn more about debugging WordPress." after the first post displayed.

here is my entire code :

<?php  add_action('wp_ajax_nopriv_filter', 'filter_ajax'); add_action('wp_ajax_filter','filter_ajax');  function filter_ajax(){  $  category = $  _POST['category'];  $  argsf = array(     'post_type' => 'post',     'posts_per_page' => -1,     'order' => 'ASC' );  if(isset($  category)){     $  argsf['category__in'] = array($  category); }  $  postsf = get_posts($  argsf);      if (!empty($  postsf)) {     foreach ($  postsf as $  post) {                  $  link_post = get_permalink( $  post->ID );         $  image_post = get_the_post_thumbnail_url( $  post->ID, $  size = 'large' );         $  item1 = get_post_meta($  post->ID, 'item1', true);         $  item2 = get_post_meta($  post->ID, 'item2', true);         $  item3 = get_post_meta($  post->ID, 'item3', true);         $  item4 = get_post_meta($  post->ID, 'item4', true);         $  title = get_the_title($  post->ID);          $  post_slug = $  post->post_name;         $  cats_post = wp_get_post_categories( $  post->ID );                  function test($  cats_post){             if (in_array("14", $  cats_post)){ echo'#710000';}             elseif(in_array("5", $  cats_post)){ echo'#0a005d';}             elseif(in_array("16", $  cats_post)){ echo'#65a0e8';}             elseif(in_array("13", $  cats_post)){ echo'#90744b';}         }      ?>   <div class="shop w-24 pb-1" style="height:320px; min-width:320px;">     <div class="w-100 h-100 p-2">                      <div class=" " style="background-color:<?php test($  cats_post); ?>">             <div class="">                 <!--<div class="" title="Locer">                 <a href="<?= $  item2; ?>"><i class="icofont-opposite "></i></a>                 </div>-->                 <div class="" title="something">                     <a href="tel:<?= $  item3; ?>"><i class="im im-phone"></i> </a>                 </div>                 <div class="">                     <span><?= $  item1; ?></span>                 </div>              </div>             <span class="text-uppercase col-white tsh332 fwlr text-center" style="font-size:2rem;">                 <?= $  title; ?>             </span>             <?php if ( metadata_exists( 'post', $  post->ID , 'item4' ) ){ ?>                  <div class="">                     <div class="b-yellow b-100">                         <span><?= $  item4; ?> </span>                     </div>                 </div>             <?php } ?>         </div>                      </div> </div> <?php  }  /* fin foreach */     }  /* fin if  */ wp_reset_postdata(); die(); } 

?>

I tried that but it doesn’t work :

  • get_the_category instead of wp_get_post_categories
  • has_item instead of in_array

I don’t know If I must use an other foreach loop and how !

thanks

Smodels Algorithm, Stuck in Loop

I’m currently learning the Smodels algorithm. The specific program is: a:-b, not a. b:- not c. c:- not b.

When using the algorithm, the calculation of L (L u Cn(P^U)) leads me to ∅ U Cn(P^{a,b,c}) Applying the Gelfond Lifschitz reduct to the program with {a,b,c} leads to ∅ (all rules are deleted [or are they?]) and for the calculation of U (U n Cn(P^L)) leads me to {a,b,c}.

Solving the problem with a logic compiler gives me the answerset {c}, but due to aboves problem, I’m stuck in an infinite loop.

What am I missing?

Thanks in advance for any help

PS: "u" is for XOR and "n" for union

Code to Update Prices and add them for Woocommerce Custom Product Variations Loop

I am actually struggling with some custom functions. Actually My aim is the following: Create 2 custom fields in a woocommerce variable product backend ✔ Show these custom fields text and prices in frontend Make able to add the product in the cart with these prices summed up.

I don’t know which hook I am using wrong and why the theme ajax doesn’t work. There is someone that can assist?

"Working" (I hope) Code

// Aggiunte campi asseverazione, legalizzazione Variazioni nel backend add_action( 'woocommerce_variation_options_pricing', 'add_variation_options_pricing_assev', 10, 3 ); function add_variation_options_pricing_assev( $  loop, $  variation_data, $  variation ){      woocommerce_wp_text_input( array(         'id' => '_assev_'.$  loop,         'wrapper_class' => 'form-row form-row-first',         'class' => 'short wc_input_price',         'label' => __( 'Asseverazione', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',         'value' => wc_format_localized_price( get_post_meta( $  variation->ID, '_assev', true ) ),         'data_type' => 'price',     ) );     woocommerce_wp_text_input( array(         'id' => '_legal_'.$  loop,         'wrapper_class' => 'form-row form-row-last',         'class' => 'short wc_input_price',         'label' => __( 'Legalizzazione', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',         'value' => wc_format_localized_price( get_post_meta( $  variation->ID, '_legal', true ) ),         'data_type' => 'price',     ) );      }  // Salvataggio in backend add_action( 'woocommerce_save_product_variation','save_variation_options_pricing_assev', 10, 2 ); function save_variation_options_pricing_assev( $  variation_id, $  loop ){     if( isset($  _POST['_assev_'.$  loop]))         update_post_meta( $  variation_id, '_assev', wc_clean( wp_unslash( str_replace( ',', '.', $  _POST['_assev_'.$  loop] ) ) ) );     if( isset($  _POST['_legal_'.$  loop]))         update_post_meta( $  variation_id, '_legal', wc_clean( wp_unslash( str_replace( ',', '.', $  _POST['_legal_'.$  loop] ) ) ) ); }  // Frontend (mi manca di aggiungere la legalizzazione) add_filter( 'woocommerce_available_variation', 'display_variation_assev', 10, 3 );  function display_variation_assev( $  data, $  product, $  variation ) {      if( $  assev = $  variation->get_meta('_assev') ) {         $  data['price_html'] = '<div class="woocommerce_assev">' . __( 'Asseverazione: ', 'woocommerce' ) .         '<span class="asseverazione-prezzo">' . wc_price( $  assev ) . '</span></div>' . $  data['price_html'];     }      return $  data; } 

Code Struggle:

/*add_filter( 'woocommerce_add_cart_item', 'aggiorna_prezzi_nuova', 10, 2 ); function aggiorna_prezzi_nuova( $  cart_item_data, $  cart_item_key, $  variation) {                if( isset( $  _POST['_assev_'][$  variation_id] ) )         $  cart_item_data['_assev'][$  variation_id] = $  _POST['_assev'][$  variation_id];     if(isset( $  _POST['_legal'] ) )        $  cart_item_data['_legal'] = $  _POST['_legal'];      return $  cart_item_data; }   add_action( 'woocommerce_before_calculate_totals', 'fissa_valore_var_carrello', 20, 1 ); function fissa_valore_var_carrello( $  cart ) {     if ( is_admin() && ! defined( 'DOING_AJAX' ) )         return;      if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )         return;      // First loop to check if product 11 is in cart     foreach ( $  cart->get_cart() as $  cart_item ){         if( isset($  cart_item['_assev']) && isset($  cart_item['_legal'])          && ! empty($  cart_item['_assev']) && ! empty($  cart_item['_legal']) )             $  cart_item['data']->set_price( '30' );     } }*/ 

Other non functional code:

function aggiorna_prezzo( $  price, $  product ) {         $  shortcost_first = get_post_meta( $  variation->id, '_assev_0', true );    $  shortcost_mid = get_post_meta( $  product->id, '_assev_0', true );   $  shortcost_minimum = get_post_meta( $  product->id, 'assev_0', true );        $  unit_price = $  assev + $  shortcost_mid + $  shortcost_first + $  shortcost_minimum; //     +($  shortcost_mid * ($  shortcost_minimum - 1));    return $  price + $  unit_price;       } add_filter('woocommerce_get_price', 'aggiorna_prezzo', 10, 3); add_filter('woocommerce_get_regular_price','aggiorna_prezzo', 10, 3); add_filter('woocommerce_get_sale_price','aggiorna_prezzo', 10, 3); 

Thank you!

How to make variable update for each instance of for-each loop?

I have a for-each loop that goes through a file directory. These files are transaction information from different clients. When there is an error with a file (i.e. can’t be processed), the Event Handler is to send an email to the client notifying them. There is a SQL task that uses an existing variable (Client ID from the file) that queries a table to get the Client’s email address. I created a variable for the Client Email. I want to make this update each time the for-each loop is run, since each file will have a different value for the client email variable.

How can I ensure this?

Inside the for-each loop, there are three data flow tasks that could conceivably "error" and that’s when I will be sending these notification emails. Will I need to scope a variable for each of the three executables within the loop for the Client Email? Or can I scope a single variable in the for-each loop?

I understand this may be a bit confusing so please let me know if you have any questions.

Event Handler Flow

For-Each loop with data flow task

How do you output custom code before a subset of posts in the loop?

I have a foreach loop for a custom post type ordered by date (meta key). If a post’s associated date is less than the current date (i.e., dates not in the future), I want to output some HTML. if ($ custom_post_date >= $ today && $ index === 1) The problem I am running into is that the HTML gets output after the first post that is in the past. How can I output the HTML before the first post that meets the criteria? Is there a way to go back in the foreach loop or something to that effect?