Preferred way of cacheing a value in php

You want the Transients API: get_transient and set_transient (and get/set_site_transient). These store values in the wp_options table with a namespace and expiry date, so they do persist through page reloads. (As does anything stored in the database, unless you explicitly create per-connection temporary tables.)

Retrieving Author ID in wp-admin area

It can be done like this without having to rely on the $post global. if ( is_admin() ) { if( isset( $_GET[‘post’] ) && isset( $_GET[‘action’] ) && $_GET[‘action’] === ‘edit’ ) { $post_id = $_GET[‘post’]; $current_post = get_post($post_id); $author_id = $current_post->post_author; } } The query string variable post is always the post_id you are … Read more

class click counter save number

Made ajax call as a function to avoid the Console Error 400 Post. It opens the channel and I was able to get the parameters passed. counter.js jQuery(document).on(‘click’,’.counter’,function(e){ testAjax(the_ajax_script.ajaxurl); }); function testAjax(link) { $.ajax({ url: link, type: ‘post’, data: { ‘action’: ‘set_button_count’, ‘increase’ : ‘1’ }, success: function(data) { jQuery(‘.count’).html(data); } }); } In functions.php … Read more

get current product name in functions.php

Please check below code : add_action( ‘woocommerce_single_product_summary’,’content_after_addtocart_button’ ); function content_after_addtocart_button() { global $product; $product_title = $product->get_name(); $product_price = $product->get_price(); echo ‘<div class=”content-section”> <a href=”https://wordpress.stackexchange.com/questions/340361/mailto:[email protected]?&subject=Richiesta Informazioni&body=” . $product_title . ‘??? ‘ . $product_price . ‘ ??? “> <input type=”button” value=”Richiedi Informazioni”/ ></a></div>’; }

display month in french in wordpress/php?

there is a custom function in wordpress called date_i18n. so basically you do echo date_i18n( ‘H:i d-m-Y’, $ts ); without the setLocale stuff.. find the function date_i18n and its parameters here. you could even build in your translation all in there, without the language check before: date_i18n( __( ‘H:i d-m-Y’, ‘textdomain’ ) ); (replace ‘textdomain’ … Read more

understanding if statement [closed]

the code is executed when post type is post or page No, only if the post type is page (because of the ‘page’ == $screen->id). Because that if statement actually checks if the current admin screen is the one for editing or creating a Page (post type of page), where the URL looks like so: … Read more

putting Mailto: and Tel: into footer.php code wordpress

Please edit your code as below: <address class=”address_phone”> <span class=”icon icon-phone”></span> <div class=”contact_title”><?php echo esc_html__(‘Phone:’, ‘yogastudio’) ?></div> <span class=”contact_item phone”> <?php if (!empty($phone)) { echo ‘<a href=”https://wordpress.stackexchange.com/questions/346269/tel:”.$phone.'”>’.esc_html($phone).'</a>’;} ?> </span> </address></div><div class=”column-1_3″> <address class=”address_email”> <span class=”icon icon-mail”></span> <div class=”contact_title”><?php echo esc_html__(‘Email:’, ‘yogastudio’) ?></div> <span class=”contact_item mail”><?php if (!empty($email)) { echo ‘<a href=”https://wordpress.stackexchange.com/questions/346269/mailto:”.$email.'”>’.esc_html($email).'</a>’;}?></span> </address></div>