Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
chuckreynolds / wordpress-change-domain-migration.sql
Last active February 10, 2023 18:56
UPDATE: Use WP-CLI find-replace command to edit URLs in your database. https://developer.wordpress.org/cli/commands/search-replace/ Use this SQL script when changing domains on a WordPress site. Whether you’re moving from an old domain to a new domain or you’re changing from a development domain to a production domain this will work. __STEP1: al…
/* Use WP-CLI instead https://developer.wordpress.org/cli/commands/search-replace/ */
SET @oldsite='http://oldsite.com';
SET @newsite='http://newsite.com';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);
/* only uncomment next line if you want all your current posts to post to RSS again as new */
@aderaaij
aderaaij / acf-future-posts.php
Last active February 8, 2024 14:29
Advanced Custom Fields datepicker: Show only events with a date of today or in the future. Extra comments from Pasnon @ ACF Forums: f you needed to, you could also play with the comparison date, which is the first array in meta_query, currently set to date("Y-m-d") which is today; if you were to make it date("Y-m-d", strtotime("-1 day")) you cou…
<?php
/*
* Display posts only from today and in the future:
* http://old.support.advancedcustomfields.com/discussion/6000/how-to-sort-posts-by-acf-date-and-display-only-future-posts
* by Pasnon
*/
$date_args = array(
'post_type' => 'events',
@hissy
hissy / gist:7352933
Created November 7, 2013 11:07
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
@fdaciuk
fdaciuk / css-vertical-align.css
Created November 21, 2013 18:01
Magia para alinhar imagem na vertical
span {
display: inline-block;
height: 100%;
vertical-align: middle;
}
img {
display: inline-block;
vertical-align: middle;
}
@fdaciuk
fdaciuk / my_wp_is_mobile.php
Created December 5, 2013 11:14
wp_is_mobile personalizada para não usar no iPad
<?php
function my_wp_is_mobile() {
if (
! empty($_SERVER['HTTP_USER_AGENT'])
// bail out, if iPad
&& false !== strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')
) return false;
return wp_is_mobile();
} // function my_wp_is_mobile
@Shelob9
Shelob9 / reorder-cpt-archive.php
Created February 5, 2014 21:25
Reorder a WordPress custom post type archive page by the value of a meta field. Based on this SE answer: http://wordpress.stackexchange.com/a/48658/25300
<?php
function slug_order_archive_by_field( $query ) {
//Only do if is main query fo a specific cpt's archive.
//@TODO set cpt's name
if ( $query->is_main_query() && is_post_type_archive( 'CPT_NAME' ) ) {
//@TODO Set the name of the field we are ordering by
$query->set( 'meta_key', 'FIELD_NAME' );
//@TODO change order to DESC IF you want to go in reverse order
$query->set( 'order', 'ASC' );
//@TODO uncomment next line IF you want to sort by an integer instead of alphabetically
@azizur
azizur / create-wp-admin-account.sql
Last active September 28, 2021 15:39
Create a WordPress Administrator user account using SQL
USE __DATABASE__;
SET @username = 'azizur';
SET @password = MD5('password');
SET @fullname = 'Azizur Rahman';
SET @email = '[email protected]';
SET @url = 'http://azizur.com/';
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_status`, `display_name`) VALUES (@username, @password, @fullname, @email, @url, NOW(), '0', @fullname);
@brycejacobson
brycejacobson / functions.php
Created February 11, 2014 17:14
Programmatically add menu Item in WordPress
<?php
add_filter( 'wp_nav_menu_items', 'add_logout_link', 10, 2);
/**
* Add a login link to the members navigation
*/
function add_logout_link( $items, $args )
{
if($args->theme_location == 'site_navigation')
@moneal
moneal / gist:9859180
Created March 29, 2014 18:03
Disable WordPress script concatenation.
/**
* Disable script concatenation.
* If WordPress's dashboard isn't loading styles from load-styles.php
* add this to wp-config.php to disable concatenation and load styles that
* don't have errors
*/
define( 'CONCATENATE_SCRIPTS', false );
@benwells
benwells / batch_rename.sh
Created April 7, 2014 15:22
Batch renaming files in a directory using bash
# Batch renaming/mv/cp/etc... using bash
# Step 1: to make a backup copy of all pdf files in a directory
for i in *.pdf ; do mv "$i" "${i}.backup" ; done
# Step 2: to copy one file over all of the original files in this directory
for i in *.pdf ; do cp "~/source.pdf" "${i}" ; done