Skip to content

Instantly share code, notes, and snippets.

@nciske
nciske / get_meta_values.php
Created September 18, 2012 17:40
WordPress Getting all values for a custom field key
// http://wordpress.stackexchange.com/questions/9394/getting-all-values-for-a-custom-field-key-cross-post
function get_meta_values( $key = '', $type = 'post', $status = 'publish' ) {
global $wpdb;
if( empty( $key ) )
return;
$r = $wpdb->get_col( $wpdb->prepare( "
SELECT pm.meta_value FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
WHERE pm.meta_key = '%s'
@nciske
nciske / run_embed_shortcode.php
Created September 3, 2012 21:42
WordPress Run oEmbed Shortcode
// http://wordpress.org/support/topic/call-function-called-by-embed-shortcode-direct
// Doesn't work:
// $post_embed = do_shortcode('[embed]your-video-url[/embed]');
// Does work:
global $wp_embed;
$post_embed = $wp_embed->run_shortcode('[embed]your-video-url[/embed]');
@nciske
nciske / filter-nav-menus.php
Last active July 29, 2022 10:00
Filter nav menus to allow shortcodes in labels and domain agnostic URLs
<?php
// Add a custom menu item with the URL "_SITEURL_/test" and label "[test]" to see it in action
add_filter('wp_nav_menu', 'menu_shortcodes');
function menu_shortcodes( $menu ){
return str_replace('_SITEURL_',preg_replace("~^(?:f|ht)tps?://~i", '', home_url() ), do_shortcode( $menu ) );
}
@nciske
nciske / wpdb-transactions
Last active April 24, 2022 13:45 — forked from 5iDS/wpdb-transactions
MySQL database transaction, using the WordPress database object $wpdb. Requires the InnoDB table format.
<?php
global $wpdb;
// Start Transaction
$wpdb->query( "START TRANSACTION" );
// Do some expensive/related queries here
//$wpdb->query("DELETE FROM table WHERE form_id = '1' ");
//$wpdb->query("DELETE FROM data WHERE form_id = '1' ");
// set $error variable value in error handling after $wpdb modifications
@nciske
nciske / speedmail.applescript
Last active February 8, 2021 20:03 — forked from ttscoff/speedmail.applescript
Speed up Mail.app
(*
Speed up Mail.app by vacuuming the Envelope Index
Code from: http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/
Originally by "pmbuko" with modifications by Romulo
Updated by Brett Terpstra 2012
Updated by Mathias Törnblom 2015 to support V3 in El Capitan and still keep backwards compability
Updated by @lbutlr for V5 and Container folder in High Sierra and use du
Updated by @nciske for V6 in Mojave
NOTE: Mojave users will need to grant Terminal.app or Automator.app (wherever you run the script) full disk access for the script to run successfully
@nciske
nciske / add_screenshot_as_ogimage.php
Last active January 19, 2021 02:36
Add screenshot of current page as Open Graph image. Primes the wp.com cache by including the image at the bottom of the page as well.
<?php
add_action( 'wp_head', 'add_screenshot_as_ogimage' );
function add_screenshot_as_ogimage(){
// default width = 1500 -- 200px minimum, Facebook recommends 1500x1500, max image size of 5mb
echo '<meta property="og:image" content="http://s.wordpress.com/mshots/v1/'.urlencode( $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ).'?w=1500"/>';
@nciske
nciske / gform-na-currency.php
Created July 30, 2014 14:51
Gravity Forms - Currency with no symbol. For those edge cases where the amount could be in any number of denominations.
<?php
add_filter("gform_currencies", "add_na_currency");
function add_na_currency($currencies) {
$currencies['NA'] = array(
"name" => __("N/A", "gravityforms"),
"symbol_left" => '',
"symbol_right" => "",
"symbol_padding" => " ",
@nciske
nciske / co-authors-list.php
Last active April 6, 2019 07:43
List just co-authors with thumbnail
<?php
$args = array( 'post_type' => 'guest-author', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' );
$guest_authors = get_posts( $args );
foreach( $guest_authors as $ga ){
echo '<div class="contributor">';

Keybase proof

I hereby claim:

  • I am nciske on github.
  • I am nciske (https://keybase.io/nciske) on keybase.
  • I have a public key ASB7t0EWCIBKKd78Pn8E9eLBX8J-NpP-_diJHTGvUp4LBgo

To claim this, I am signing this object:

@nciske
nciske / default-template.php
Created January 2, 2014 20:25
Default page template for The Events Calendar and Genesis 1.9 themes.
<?php
/**
* Default Events Template for Genesis
* This file is the basic wrapper template for all the views if 'Default Events Template'
* is selected in Events -> Settings -> Template -> Events Template.
*
* @package TribeEventsCalendar
* @since 3.0
* @author Modern Tribe Inc. | Tweaked by Thought Refinery
*