Skip to content

Instantly share code, notes, and snippets.

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 Feb 4, 2014
set up 404 redirects from /%postname%/ to /blog/%category%/%postname%/
View structure-redirects.php
<?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 Feb 19, 2014
set custom menu order
View custom-menu-order.php
<?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 Apr 14, 2014
CSS fixes for Sharedady to account for RWD
View sharedaddy-css.css
/** 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 Apr 18, 2014
add a secondary meta key for sorting
View agentpress-meta-sort.php
<?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 Apr 21, 2014
limit WP search to titles only
View wp-search-titles.php
<?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 / php-version-check.php
Created Apr 21, 2014
quick example of how version_compare works
View php-version-check.php
<?php
header('Content-type: text/plain');
$versions = array(
'1',
'1.0',
'1.01',
'1.1',
'1.1.0',
'1.1.1b',
@norcross
norcross / keybase.md
Created Apr 21, 2014
keybase verification
View keybase.md

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 / all-posts-from-taxonomy.php
Created May 14, 2014
get posts with any term within a taxonomy
View all-posts-from-taxonomy.php
<?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
set publish box to float down side of editor
View publish-box-float.js
$( '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 Aug 29, 2015
add a dropdown with all node IDs in the admin bar
View admin-bar-nodes.php
<?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)
*/