Вопрос

I'm using Buddypress 1.8.1

When the group home page load I want to show only 'activity_update' and 'joined_group' activities in Activity Loop.

Here is my Activity Loop code. It is standard loop code.

<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?>
    <?php while ( bp_activities() ) : bp_the_activity(); ?>

        <?php locate_template( array( 'activity/entry.php' ), true, false ); ?>

    <?php endwhile; ?>
<?php endif; ?>

How to filter these activities in page load?

Это было полезно?

Решение

I have created this function in bp-custom.php page.

function filtering_activity_default( $query ) {
  if ( empty( $query ) && empty( $_POST ) ) {
    $query = 'action=activity_update,joined_group';
  }
  return $query;
}

add_filter( 'bp_ajax_querystring', 'filtering_activity_default', 999 );

This is working for me as expected.

Другие советы

Use the filters: BP Codex

IN your case, it would be

if ( bp_has_activities( 'action=activity_update,joined_group' ) ) : 

bp_has_activities is used for both Activity and Group Activity.

So if you only want to apply the filter to Group Activity, you can either:

  • use bp_is_group() to determine if you're on a group page.
  • or override the template used for Group Activity.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top