Last active
August 29, 2015 14:26
-
-
Save KingYes/d072769d3f67acaaf375 to your computer and use it in GitHub Desktop.
Added custom post in Pojo Recent Posts Widget
This file contains hidden or 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
/** | |
* @param array $fields | |
* @param WP_Widget $widget_obj | |
* | |
* @return array | |
*/ | |
function pojo28831_add_custom_post_type_in_recent_posts_widget( $fields, $widget_obj ) { | |
$fields[] = array( | |
'id' => '_custom_post_type', | |
'title' => __( 'Post Type:', 'pojo' ), | |
'type' => 'select', | |
'std' => '', | |
'options' => array( | |
'' => __( 'Post', 'pojo' ), | |
'YOUR_CPT_SLUG' => __( 'Custom Post Type', 'pojo' ), | |
), | |
'filter' => array( &$widget_obj, '_valid_by_options' ), | |
); | |
return $fields; | |
} | |
add_filter( 'pojo_recent_posts_widget_fields_after_metadata', 'pojo28831_add_custom_post_type_in_recent_posts_widget', 10, 2 ); | |
/** | |
* @param array $query_args | |
* @param array $instance | |
* | |
* @return string|array | |
*/ | |
function pojo28831_change_query_args_for_custom_post_type( $query_args, $instance ) { | |
if ( ! empty( $instance['_custom_post_type'] ) ) { | |
$query_args['post_type'] = $instance['_custom_post_type']; | |
} | |
return $query_args; | |
} | |
add_filter( 'pojo_recent_posts_widget_query_args', 'pojo28831_change_query_args_for_custom_post_type', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment