WP_Query By Most Popular Posts
Click link below
WPBeginner
Click link below
WPBeginner
print();
let timer = setInterval(function() {
// The dispatch date is just the variable name. You can change it wo whatever. As long as you change it where ever else it is been used as well.
// the format for dispatch_date is ('2018-10-17 17:00:00') which is been pull from an input field with the id of "countdown_timer"
const dispatch_date = new Date(document.getElementById("countdown_timer").value);
const today = new Date();
// console.log("dispatch_date : "+dispatch_date);
// console.log("today : "+today);
// get the difference
const diff = dispatch_date - today;
// math
let days = Math.floor(diff / (1000 * 60 * 60 * 24));
let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((diff % (1000 * 60)) / 1000);
// display
document.getElementById("timer").innerHTML =
//Days - Hours - Minutes - Seconds
"</div class='timer-p'>This Stock list Expires in </div> \ <div class=\"days\"> \
<div class=\"numbers\">" + days + "</div>Days</div> \
<div class=\"hours\"> \
<div class=\"numbers\">" + hours + "</div>Hours</div> \
<div class=\"minutes\"> \
<div class=\"numbers\">" + minutes + "</div>Minutes</div> \
<div class=\"seconds\"> \
<div class=\"numbers\">" + seconds + "</div>Seconds</div> \
</div>";
}, 1000);
Here’s the Stackoverflow link
Here’s the improved answer
//The Function
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
$found = 'yes';
}
}
$found = 'no';
return false;
}
//The Function in use
//Set the result as a var so you can check it.
$found = in_array_r($search_pre_order_date,$dates_array) ? 'found' : 'not found';
//If the result is equal to something do something...
if ($found == 'found') {
echo 'Yes this item is in the array';
}elseif ($found == 'not found') {
echo 'Nope not in the array';
}
add_action( 'admin_head', 'remove_my_meta_boxen' );
function remove_my_meta_boxen() {
remove_meta_box( 'postimagediv', 'countries', 'side' );
add_meta_box('postimagediv', __('Country Flag'), 'post_thumbnail_meta_box', 'countries', 'side', 'high');
}
The post type in this example is countries
<a href="javascript:history.go(-1)" class="custom_back_button"><i class="fas fa-chevron-left"></i> Back</a>
This example uses Font Awesome. Don’t forget to include Font Awesome lib in your functions.php
jQuery(document).ready(function($) {
// Test
console.log( "ready!" );
});
The code below relates to the meta box plugin. And the code below relates to 2 custom post types. Players and Coaches. And then adding meta fields to those custom post types.
// Custom Post 1
register_post_type( 'coaches',
array(
'labels' => array(
'name' => __( 'Coaches' ),
'singular_name' => __( 'Coach' )
),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail')
)
);
register_taxonomy_for_object_type( 'category', 'coaches' );
// Custom Post 2
register_post_type( 'players',
array(
'labels' => array(
'name' => __( 'Players' ),
'singular_name' => __( 'Player' )
),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail')
)
);
register_taxonomy_for_object_type( 'category', 'players' );
// Meta Fields
function add_meta_fields( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'twitter_url',
'title' => 'Twitter Url' ,
'post_types' => array( 'players','coaches' ),
'context' => 'normal',
'autosave' => false,
'fields' => array(
array(
'id' => 'twitter_url',
'type' => 'url',
'name' => 'URL',
),
),
);
$meta_boxes[] = array(
'id' => 'instagram_url',
'title' => 'Instagram Url' ,
'post_types' => array( 'players','coaches' ),
'context' => 'normal',
'autosave' => false,
'fields' => array(
array(
'id' => 'instagram_url',
'type' => 'url',
'name' => 'URL',
),
),
);
$meta_boxes[] = array(
'id' => 'facebook_url',
'title' => 'Facebook Url' ,
'post_types' => array( 'players','coaches' ),
'context' => 'normal',
'autosave' => false,
'fields' => array(
array(
'id' => 'facebook_url',
'type' => 'url',
'name' => 'URL',
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'add_meta_fields' );
Below is how to add a location/Address field
// Address
$meta_boxes[] = array(
'id' => 'address',
'title' => 'Address' ,
'post_types' => array( 'countries' ),
'context' => 'normal',
'autosave' => false,
'fields' => array(
array(
'id' => 'address',
'name' => 'Address',
'type' => 'text',
),
array(
'id' => 'map',
'name' => 'Location',
'type' => 'map',
// Default location: 'latitude,longitude[,zoom]' (zoom is optional)
'std' => '-6.233406,-35.049906,15',
// Address field ID
'address_field' => 'address',
// Google API key
'api_key' => 'AIzaSyBVKag0eBXXIjS0rvi6qUYZ9sScw5kNeXQ',
),
),
);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Styles and Scripts
add_action('admin_head', 'my_custom_styles_and_scripts');
function my_custom_styles_and_scripts() {
echo '
<script src="/wp-content/plugins/webfootprint-stock-manager-old/assets/js/scripts.js"></script>
<link href="/wp-content/plugins/webfootprint-stock-manager-old/assets/css/styles.css" rel="stylesheet">
';
}
$woocommerce->cart->empty_cart();