Created
August 14, 2014 10:11
-
-
Save tomhemsley/6041d51dc480e21ddac9 to your computer and use it in GitHub Desktop.
Meta Slider by Slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Filter the shortcode attributes. | |
* If the ID parameter is not an integer, assume it is a slug. | |
* Convert the slug to an ID and return the attributes. | |
*/ | |
function metaslider_shortcode_slug( $atts ) { | |
if ( isset( $atts['id'] ) && ! is_int( $atts['id'] ) ) { | |
$slider = get_page_by_path( $atts['id'], OBJECT, 'ml-slider' ); | |
if ( $slider ) { | |
$atts['id'] = $slider->ID; | |
} | |
} | |
return $atts; | |
} | |
add_filter('shortcode_atts_metaslider', 'metaslider_shortcode_slug', 10, 3); | |
/** | |
* Ensure the post_name (slug) is updated when a slideshow title | |
* is updated. | |
*/ | |
function metaslider_update_slug_on_save( $data , $postarr ) { | |
if ( isset( $postarr['post_type'] ) && $postarr['post_type'] == 'ml-slider' ) { | |
$data[ 'post_name' ] = sanitize_title( $postarr[ 'post_title' ] ); | |
} | |
return $data; | |
} | |
add_filter( 'wp_insert_post_data' , 'metaslider_update_slug_on_save' , 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment