PHP Dates broken down parameters
<?php 
  echo date_default_timezone_set('UTC');
  /* The terrminology for this function
    h : 12 hour format
    H : 24 hour format
    i : Minutes
    s : Seconds
    u : Microseconds
    a : Lowercasw am or pm
    l : Full text for the day
    F : Full text for the month
    j : Day of the month
    S : Suffix for the day st, nd, rd, etc
    Y : 4 digit y
    e : timezone
  */
  echo date('h:i:s:u a, l F jS Y e');
$h = 'h'; 
$H = 'H'; 
$i = 'i'; 
$s = 's'; 
$u = 'u'; 
$a = 'a'; 
$l = 'l'; 
$F = 'F'; 
$j = 'j'; 
$S = 'S'; 
$Y = 'Y'; 
$e = 'e';
echo "12 hour format : ";echo date($h); echo "<br>";
echo "24 hour format : ";echo date($H); echo "<br>";
echo "Minutes : ";echo date($i); echo "<br>";
echo "Seconds : ";echo date($s); echo "<br>";
echo "Microseconds : ";echo date($u); echo "<br>";
echo "Lowercasw am or pm : ";echo date($a); echo "<br>";
echo "Full text for the day : ";echo date($l); echo "<br>";
echo "Full text for the month : ";echo date($F); echo "<br>";
echo "Day of the month : ";echo date($j); echo "<br>";
echo "Suffix for the day st, nd, rd, etc : ";echo date($S); echo "<br>";
echo "4 digit y : ";echo date($Y); echo "<br>";
echo "timezone : ";echo date($e); echo "<br>";
?>
WordPress Update meta_value by meta_key
// Clear Stock
function clear_current_stock(){ 
// Declare the $wpdb var
    global $wpdb;
// Run My SQL Query (My Query is setting the meta value for stock to zero)
    $wpdb->query("UPDATE wp_postmeta SET meta_value = 0 WHERE meta_key = '_stock'");
// Check if there were any errors or if my query was successful.
    if ( is_wp_error( $wpdb ) ) {
         echo $wpdb->get_error_message();
    }
    else {
         echo 'true';
    }
}

Then you can call the function like this

<?php clear_current_stock(); ?>
Check User Role ( if statement included )
<?php
  $user_id = get_current_user_id();
  if (!empty($user_id)) {
  $user = wp_get_current_user();
  $role = ( array ) $user->roles;
  // echo $role[0];
  if ($role[0] == 'free-client' OR $role[0] == 'administrator') {
    //code here...
  }
  }
?>
PHP Delete Cookie
<?php
// set the expiration date to one hour ago
  setcookie("user", "", time() - 3600);
?>

<?php
  echo "Cookie 'user' is deleted.";
?>
PHP Set Cookie and Retrieve Cookie
<?php
  $cookie_name = "user";
  $cookie_value = "Alex Porter";
  setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
?>

<?php
  if(!isset($_COOKIE[$cookie_name])) {
       echo "Cookie named '" . $cookie_name . "' is not set!";
  } else {
       echo "Cookie '" . $cookie_name . "' is set!<br>";
       echo "Value is: " . $_COOKIE[$cookie_name];
  }
?>

Search

Your Favourite Posts

  • Your favorites will be here.

Latest Content

© Garth Baker 2025 All rights reserved.

Pin It on Pinterest

Share This