Skip to content

Instantly share code, notes, and snippets.

View norcross's full-sized avatar
somone said this would be easy. someone LIED.

Norcross norcross

somone said this would be easy. someone LIED.
View GitHub Profile
@norcross
norcross / structure-redirects.php
Created February 4, 2014 16:08
set up 404 redirects from /%postname%/ to /blog/%category%/%postname%/
<?php
/** set up redirects from old structure */
function aly_post_redirects() {
if ( ! is_user_logged_in() )
return;
if ( is_404() ) :
$slug = $_SERVER['REQUEST_URI'];
@norcross
norcross / custom-menu-order.php
Created February 19, 2014 21:17
set custom menu order
<?php
add_filter ( 'custom_menu_order', array( $this, 'menu_order' ), 1001 );
add_filter ( 'menu_order', array( $this, 'menu_order' ), 1001 );
public function menu_order( $menu_ord ) {
if ( ! $menu_ord )
return true;
return array(
@norcross
norcross / sharedaddy-css.css
Created April 14, 2014 12:31
CSS fixes for Sharedady to account for RWD
/** ShareDaddy
* ----------------------------------------------------------------------------
*/
body.custom .entry-content div.sharedaddy {
margin: 20px 0 0;
}
body.custom .entry-content div.sharedaddy .sd-block {
border-top: 1px dotted #ccc;
@norcross
norcross / agentpress-meta-sort.php
Created April 18, 2014 01:01
add a secondary meta key for sorting
<?php
// extra check for price that can create a sortable value
if ( isset( $property_details['_listing_price'] ) && ! empty( $property_details['_listing_price'] ) ) {
// strip anything other than a decimal
$price_sortable = preg_replace( '/[^0-9\.]/', '', $property_details['_listing_price'] );
// update the value with a floatval check
update_post_meta( $post_id, '_listing_price_sortable', floatval( $price_sortable ) );
} else {
delete_post_meta( $post_id, '_listing_price_sortable' );
}
@norcross
norcross / wp-search-titles.php
Created April 21, 2014 13:39
limit WP search to titles only
<?php
add_filter ( 'posts_search', 'rkv_search_by_title_only', 500, 2 );
/**
* restrict search query to only compare titles
* @param string $search search query passed by user
* @param mixed $wp_query global query from WP being modified
* @return mixed search results
*/
function rkv_search_by_title_only( $search, $wp_query ) {
@norcross
norcross / keybase.md
Created April 21, 2014 13:53
keybase verification

Keybase proof

I hereby claim:

  • I am norcross on github.
  • I am norcross (https://keybase.io/norcross) on keybase.
  • I have a public key whose fingerprint is E1F6 278F F814 8561 0D2E 3A5F 2AA5 6935 BA0B 15C8

To claim this, I am signing this object:

@norcross
norcross / php-version-check.php
Created April 21, 2014 14:54
quick example of how version_compare works
<?php
header('Content-type: text/plain');
$versions = array(
'1',
'1.0',
'1.01',
'1.1',
'1.1.0',
'1.1.1b',
@norcross
norcross / all-posts-from-taxonomy.php
Created May 14, 2014 23:51
get posts with any term within a taxonomy
<?php
$type = 'my-post-type';
$tax = 'my-taxonomy';
$args = array(
'post_type' => $type,
'nopaging' => true,
'tax_query' => array(
@norcross
norcross / publish-box-float.js
Created May 20, 2014 14:14
set publish box to float down side of editor
$( 'div#postbox-container-1' ).each(function() {
// set the float box
var pubBox = $( this ).find( 'div#submitdiv' );
// get our sizes and offsets
var pubWth = ( pubBox ).width();
var offTop = $( 'div#postbox-container-1' ).offset().top;
var offRgt = ( $( window ).width() - ( pubBox.offset().left + pubBox.outerWidth() ) );
@norcross
norcross / admin-bar-nodes.php
Last active August 29, 2015 14:02
add a dropdown with all node IDs in the admin bar
<?php
add_action( 'wp_before_admin_bar_render', 'rkv_node_ids_to_toolbar' );
/**
* run throught all available nodes in the global wp_admin_bar
* and create a multi level dropdown
*
* used for when you need to remove one (or more)
*/