I'm trying to write TOP5 for an activity in BuddyBoss, but I don't know what type of LIKE there is, I've tried typing rating and like.
But my code doesn't work, it displays as a widget, but there are no liked entries in the widget
Code:
But my code doesn't work, it displays as a widget, but there are no liked entries in the widget
Code:
Code:
function top_activities_24h_widget() {
register_widget( 'Top_Activities_24h_Widget' );
}
add_action( 'widgets_init', 'top_activities_24h_widget' );
class Top_Activities_24h_Widget extends WP_Widget {
function __construct() {
$widget_ops = array( 'classname' => 'top_activities_24h', 'description' => __('Najlepsze na blogu z 24h', 'top_activities_24h') );
parent::__construct( 'top_activities_24h', __('Top Rated Activities (24h)', 'top_activities_24h'), $widget_ops );
}
function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title'];
}
$top_activities_24h = new WP_Query( array(
'meta_key' => 'rating',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'date_query' => array(
array(
'after' => '24 hours ago'
)
),
'posts_per_page' => 5
) );
if ( $top_activities_24h->have_posts() ) :
echo '<ul>';
while ( $top_activities_24h->have_posts() ) : $top_activities_24h->the_post();
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
endwhile;
echo '</ul>';
endif;
wp_reset_postdata();
echo $args['after_widget'];
}
function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Top Rated Activities (24h)', 'top_activities_24h' );
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
</p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}