1+1 php counter inside the update_post_meta

If you’re trying to update the number stored in the meta table, you need to load that value and increment it. $count = get_post_meta( $bid_id, ‘draftnumber’, true ); if ( ! $count ) { $count = 0; // if the meta value isn’t set, use 0 as a default // We’ll be incrementing this right … Read more

how to get the value of time left for a transient

The problem here is that if the site is actually using something like Redis, or any other supported “external cache” then nothing is going to actually be set in the options table (which can be checked with wp_using_ext_object_cache) Storage in the options table is just how WordPress handles transients outside of any external caching (or … Read more

register_activation_hook isn’t adding table to DB

Note that the $file in register_activation_hook( $file, $callback ), should be equal to path to the main plugin file, but when you have it in a sub file as __FILE__ then it’s not the same! That means your callback is never called. I would also recommend prefixing the function’s name to avoid possible name collision … Read more

When did wordpress switched requirements to php7?

The currently required minimal PHP version is still 5.2.4+. The recommended version is 7. According to archive.org since December 2, 2016. Note that many plugins and themes need at least PHP 5.4 or newer nowadays, and that PHP versions below 5.6 do not get security updates anymore and are therefore probably not safe for production. … Read more

PHPCS: Strings should have translatable content

There are several things wrong with your code The is no need for translation there. The message should have been translated before it is being passed to that function. At that function there is actually no context at all to create any different translation than %s Escaping should happen at the output. You should escape … Read more

How do I add HTML to a PHP function [closed]

You can use ‘echo’ (or ‘print’) to enclose HTML, but sometimes that gets a bit messy with complex HTML, not to mention having to escape quote/double-quote character. So try something like this: function myfunction() { // after this next, plain HTML ?> <div class=”myclass”><h1 align=”center”>This is a heading</h1></div> <!– more HTML code here –> <?php … Read more

How to change / delete product short description in Woocommerce

Th function wp_set_object_terms() will not work to set post object properties. To add/update/delete product short description there is mainly 2 ways: 1) the WordPress way from a post ID using wp_update_post() function this way: $product_id = $post->ID; // or get_the_id() or $product->get_id() (when $product is available); // The product short description (for testing) $new_short_description = … Read more