Skip to content

Instantly share code, notes, and snippets.

@KingYes
Last active Aug 29, 2015
Embed
What would you like to do?
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