by Garth | Sep 3, 2018 | PHP, Wordpress
Firstly you have your while loop to run through all your posts.
And above your while loop you have your args.
You need to add this arg
$args['paged'] = $paged;
Below is a template to start your while loop
$args['post_type'] = 'post';
$query = new WP_Query($args);
while ( $query->have_posts() ) : the_post(); ?>
<?php
$query->the_post();
$post_id = get_the_ID();
?>
<div class="card">
<a href="<?php the_permalink(); ?>" class="card-header text-center">
<?php
the_title();
?>
</a>
<div class="card-body">
<?php
the_content();
?>
</div>
</div>
<?php endwhile; ?>
Your Args must be before your Query!
Then after your endwhile. Paste this code to display your pagination links
<div class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( 'Previous', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( 'Next', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
?>
</div>
by Garth | Aug 19, 2018 | Themes, Wordpress
Materialis
by Garth | Aug 6, 2018 | Debugging, Wordpress
Define('WP_SITEURL','https://your-site-url');
Define('WP_HOME','https://your-site-url');
The above code must get added to your wp-config.php File
It should fix the redirecting login issue.
I left in inside my file after using it and all seemed fine. So no harm in just keeping it.
by Garth | Aug 2, 2018 | Javascript, Jquery
document.getElementById('id_goes_here').style.display = 'none';
by Garth | Jul 30, 2018 | PHP, Snippets, Woocommerce, Wordpress
Click link below
WPBeginner
by Garth | Jul 26, 2018 | Javascript, Snippets, Tools
print();
by Garth | Jul 26, 2018 | Javascript, Jquery, Snippets
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);
by Garth | Jul 24, 2018 | PHP, Snippets, Wordpress
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';
}
by Garth | Jul 23, 2018 | Plugins, Wordpress
Dynamic Featured Image
by Garth | Jul 23, 2018 | PHP, Snippets, Wordpress
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
by Garth | Jul 23, 2018 | HTML, Javascript, Jquery, Snippets, Tools
<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
by Garth | Jul 23, 2018 | Javascript, Jquery
jQuery(document).ready(function($) {
// Test
console.log( "ready!" );
});