Navigation überspringen

[Gelöst] Only find posts of user´s buddypress-friends in a view?

This support ticket is created vor 6 Jahren, 3 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Christian Cox vor 6 Jahren, 3 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1127624

a.R

How can I only find posts by the user´s friends, if I have an array $friends containing the friends´ user IDs?
So: how can I compare the authors of the posts I will find to that array?

THANK YOU

#1127659

Hi, you can apply custom filters to a View using the wpv_filter_query API.

add_filter( 'wpv_filter_query', 'ts_show_buddys_posts', 99, 3 );
function ts_show_buddys_posts( $query_args, $view_settings, $view_id ) {
  $views = array( 12345 ); // view IDs flat array
  if( in_array( $view_id, $views) ){
    $friends = array( 6,7,8,9 ); // author IDs flat array
    $query_args['author'] = implode(',' , $friends);
  }
  return $query_args;
}

Replace 12345 with the numeric ID of this View. Edit this View in wp-admin and remove any author Query Filters you have applied. The custom code will apply the filter automatically, overriding these settings.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters