Skip to content

Instantly share code, notes, and snippets.

@KingYes
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KingYes/d072769d3f67acaaf375 to your computer and use it in GitHub Desktop.
Save KingYes/d072769d3f67acaaf375 to your computer and use it in GitHub Desktop.
Added custom post in Pojo Recent Posts Widget
/**
* @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