Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 80 additions & 11 deletions ultimate-posts-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ class WP_Widget_Ultimate_Posts extends WP_Widget {

function WP_Widget_Ultimate_Posts() {

$widget_options = array(
'classname' => 'widget_ultimate_posts',
'description' => __( 'Displays list of posts with an array of options', 'upw' )
$widget_options = array(
'classname' => 'widget_ultimate_posts',
'description' => __( 'Displays list of posts with an array of options', 'upw' )
);

$control_options = array(
'width' => 450
);

$this->WP_Widget(
'sticky-posts',
__( 'Ultimate Posts', 'upw' ),
$this->WP_Widget(
'sticky-posts',
__( 'Ultimate Posts', 'upw' ),
$widget_options,
$control_options
);
Expand Down Expand Up @@ -112,7 +112,7 @@ function widget( $args, $instance ) {
$orderby = $instance['orderby'];
$meta_key = $instance['meta_key'];
$custom_fields = $instance['custom_fields'];

// Sticky posts
if ($sticky == 'only') {
$sticky_query = array( 'post__in' => get_option( 'sticky_posts' ) );
Expand Down Expand Up @@ -552,9 +552,9 @@ function form( $instance ) {
<select name="<?php echo $this->get_field_name('cats'); ?>[]" id="<?php echo $this->get_field_id('cats'); ?>" class="widefat" style="height: auto;" size="<?php echo $c ?>" multiple>
<option value="" <?php if (empty($cats)) echo 'selected="selected"'; ?>><?php _e('&ndash; Show All &ndash;') ?></option>
<?php
$categories = get_categories( 'hide_empty=0' );
$categories = get_all_categories( 'hide_empty=0' );
foreach ($categories as $category ) { ?>
<option value="<?php echo $category->term_id; ?>" <?php if(is_array($cats) && in_array($category->term_id, $cats)) echo 'selected="selected"'; ?>><?php echo $category->cat_name;?></option>
<option value="<?php echo $category->term_id; ?>" <?php if(is_array($cats) && in_array($category->slug, $cats)) echo 'selected="selected"'; ?>><?php echo $category->cat_name;?></option>
<?php } ?>
</select>
</p>
Expand Down Expand Up @@ -618,7 +618,7 @@ function form( $instance ) {
<label for="<?php echo $this->get_field_id( 'meta_key' ); ?>"><?php _e('Custom field', 'upw'); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id('meta_key'); ?>" name="<?php echo $this->get_field_name('meta_key'); ?>" type="text" value="<?php echo $meta_key; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Order', 'upw'); ?>:</label>
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
Expand Down Expand Up @@ -736,4 +736,73 @@ function init_wp_widget_ultimate_posts() {
}

add_action( 'widgets_init', 'init_wp_widget_ultimate_posts' );
}

function get_all_categories( $args = '' ) {
$args_tax = array(
'public' => true,
);
$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'
$taxonomies = get_taxonomies( $args_tax, $output, $operator );

$defaults = array( 'taxonomy' => $taxonomies);
$args = wp_parse_args( $args, $defaults );
$taxonomy = $args['taxonomy'];
/**
* Filter the taxonomy used to retrieve terms when calling {@see get_categories()}.
*
* @since 2.7.0
*
* @param string $taxonomy Taxonomy to retrieve terms from.
* @param array $args An array of arguments. See {@see get_terms()}.
*/
$taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args );

// Back compat
if ( isset($args['type']) && 'link' == $args['type'] ) {
_deprecated_argument( __FUNCTION__, '3.0', '' );
$taxonomy = $args['taxonomy'] = 'link_category';
}

$categories = (array) get_terms( $taxonomy, $args );

foreach ( array_keys( $categories ) as $k )
_make_cat_compat( $categories[$k] );

return $categories;
}

add_filter('upw_wp_query_args', 'upw_query', 10, 3);

function upw_query($args, $instance, $base) {

$arguments = array();
$catOb= get_post_type_object($args['post_type'][0]);
$taxonomies = $catOb->taxonomies;
$slug=$args['category_name'][0];
$taxSlug='';
foreach ( $taxonomies as $taxonomy)
{
$arg="slug=$slug";
$taxFound= get_terms($taxonomy, $arg);
if(count($taxFound) >0)
{
$taxSlug=$taxFound[0]->taxonomy;
}
}

$arguments =
array(
'post_type' => $args['post_type'][0],
'tax_query' => array(
array(
'taxonomy' => $taxSlug,
'field' => 'slug',
'terms' => $slug,
),
),
);

return array_merge($args, $arguments);
}
}