Skip to content

Instantly share code, notes, and snippets.

View uprise10's full-sized avatar

Arjan Snaterse uprise10

View GitHub Profile
@uprise10
uprise10 / gist:3716486
Created September 13, 2012 18:30
Search users in WP
SELECT nw_users.ID,
nw_usermeta.meta_key,
nw_usermeta.meta_value,
nw_users.user_login,
nw_users.user_email
FROM nw_usermeta INNER JOIN nw_users ON nw_usermeta.user_id = nw_users.ID
WHERE (
nw_usermeta.meta_key = 'first_name'
AND nw_usermeta.meta_value LIKE '%bas%'
)
<?php
// Load all widgets from /lib/widgets directory
$widgets_path = STYLESHEET_PATH . 'lib/widgets';
$widgets_dir = @opendir( $widgets_path );
$widgets = array();
if ($widgets_dir) {
while (($entry = @readdir($widgets_dir)) !== false) {
<?php
// Put this in your functions.php or in a separate plugin if you want to show all locaitons on one page
add_action( 'pre_get_posts', 'wpseo_local_show_all_locations' );
function wpseo_local_show_all_locations( $query ) {
if( false == $query->is_main_query() || false == is_post_type_archive( 'wpseo_locations' ) ) {
return;
}
$query->set( 'posts_per_page', -1 );
@uprise10
uprise10 / gist:e5350edf222c21430729
Last active August 29, 2015 14:23
WordPress: custom number of posts for homepage only
<?php
/**
* This piece of code let you use a different number of posts for the homepage, than the default posts_per_page setting.
*/
add_action( 'pre_get_posts', 'yourprefix_filter_posts' );
add_filter('found_posts', 'yourprefix_adjust_offset_pagination', 1, 2 );
$posts_on_homepage = 7; // Custom number of posts for the homepage
@uprise10
uprise10 / change-db-dollation.php
Created September 19, 2016 08:35
Change DB collation of all tables and columns
<?php
$database_name='';
$database_username='';
$database_password='';
$connection = mysqli_connect('localhost',$database_username,$database_password);
if(!$connection) {
echo "Cannot connect to the database – incorrect details";
@uprise10
uprise10 / wp-popular-posts.php
Last active April 18, 2017 07:37
WordPress Popular posts via AJAX
@uprise10
uprise10 / exclude-author-xml-stiemap.php
Created November 16, 2017 14:02
Exclude author XML sitemap from Yoast SEO
<?php
add_filter( 'wpseo_sitemap_exclude_author', function () {
return [];
});
@uprise10
uprise10 / exclude-noindex-posts-from-search.php
Created July 31, 2018 11:03
This piece of code excludes posts from the WordPress search which have the robots meta settings on noindex, following the Yoast SEO settings.
<?php
add_action( 'pre_get_posts', function( \WP_Query $query ) {
if( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$meta_query = [
'relation' => 'OR',
[
'key' => '_yoast_wpseo_meta-robots-noindex',
'value' => '1',
'compare' => '!=',
@uprise10
uprise10 / gravity-forms-azurre-storage.php
Created March 8, 2019 12:52
When using Gravity Forms and the Microsoft Azure Storage plugin, uploaded files via a form are not automatically uploaded to Azure. This piece of code fixes that.
<?php
class Radish_GF_Azure_HandleUploads {
private static $instance;
public function __construct() {
$this->run();
}
<select>
<option value="Africa/Algiers">Africa/Algiers</option>
<option value="Africa/Cairo">Africa/Cairo</option>
<option value="Africa/Casablanca">Africa/Casablanca</option>
<option value="Africa/Harare">Africa/Harare</option>
<option value="Africa/Nairobi">Africa/Nairobi</option>
<option value="America/Argentina/Buenos_Aires">America/Argentina/Buenos_Aires</option>
<option value="America/Belize">America/Belize</option>
<option value="America/Bogota">America/Bogota</option>
<option value="America/Boise">America/Boise</option>