• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

BuddyBoss activity top5

Asfalt

New member
Oct 18, 2022
26
4
3
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:
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;
   }
}
 

Attachments

  • obraz_2023-01-08_001424503.png
    obraz_2023-01-08_001424503.png
    32.1 KB · Views: 5
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock