Skip Navigation

[Gelöst] How to show only the latest post from each author

This support ticket is created vor 3 Jahre, 6 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 Antworten, has 2 Stimmen.

Last updated by Minesh vor 3 Jahre, 5 Monate.

Assisted by: Minesh.

Author
Artikel
#1818157

On this website hidden link
I want to show only one article per author (antiquair).
In this website we have many authors. Each author has 1 or more articles.
In the upper view, I only want to show the 14 newest articles, but not more than 1 per author.
is this possible?

(in the second view we show them all, sorted on publish date.)

#1820435

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

It seems to me that you will require to use the nested view one user type view should loop through all the author users and another post type view that should help you to get the one post belong to that author.

As this will be nested views, you will not be able to sort the result based on the data but the author.

If you can share problem URL where you want to display those author post as well as access details I will setup a demo for you.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1824461

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing access details.

The thing is that either you can loop through the 14 new users and then per user we can display one article belongs to that user or either we can navigate to 14 latest articles irrespective of author.

I'm not sure now if you changed the plan as you added the post-relationship, if you can share what could be your expected output with test case example that will help me to guide you in the right direction.

#1824831

Hi Minesh,

No, not changed plan, but maybe it is usefull?

My wish in the top view is:
The newest articles, but different authors. So, when an author published 3 new articles, we will skip number 2 and 3, only show the latest.

14 tiles (articles) from 14 authors, filtered on last published.
the relationship to antiquairs is mayby usefull in making a view?

than it would be:
14 tiles from 14 antiquairs, filtered on last published article.

#1824891

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no such feature to display the result such way.

Because if you loop through the newest articles the view do not have mechanism to break the view in middle.

Here i've created the demo view:
=> hidden link

Which you can see on the frontend here:
=> hidden link

And I've added the "wpv_filter_query_post_process" filer to "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_query_post_process', 'func_filter_display_1_post_by_author', 10, 3 );
 
function func_filter_display_1_post_by_author( $query, $view_settings, $view_id ) {
  
  if($view_id == 26086) {
   
    $post_authors = array();
    $count = 0;
    $all_posts = array();
    foreach($query->posts as $k=>$v):
    	if(!in_array($v->post_author,$post_authors)){
          $count++;
          $all_posts[] = $v; 
          if($count > 13){
            break;
          }
        }
    endforeach;
    $query->posts = $all_posts;
    $query->found_posts = 14; 
    $query->post_count = 14; 
    	
    }
    return $query;
}

As you can see the view displays only 14 posts and each post is belongs to unique author.

#1829529

Hi Minesh,

This is not exactly what I was looking for. I can't add the latest article in the loop.

Is it not possible to work with an index?
I use that for the pictures in the second view.

FYI
I use your snippet now on hidden link

#1829531

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

I can't add the latest article in the loop.
==>
I'm not sure how exactly you want to add latest article to loop.

Is it not possible to work with an index?
==>
Its possible to target the specific loop index using the shortcode: [wpv-item index=1]
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-item

If you can setup a demo content and share what could be your expected output then I can review it and that will help me to guide you in the right direction.

#1829561
this-is-what-i-want.jpg
this-is-now.jpg

Hi,

I sent you 2 pictures.
I added the name of te antiquair below the article (thanks to the relationship)
This is what we like to have. Filter is removed, we don't need that here.

#1829745

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

I still not figure out from where the first image is displayed. I think its from the child post type "Artikelen" but even if the image is displayed from "Artikelen" post type, what is the reason that it should be displayed at first place with your "this-is-what-i-want.jpg".

The thing is that we do not have a way to group the posts by author until and unless either you use nested view or add custom query to filter your result.

If you use nested view where the top view will loop through the authors it will loop through all the authors and inside the author view we need to add post view that should fetch the posts belongs to that parent author passed by parent view and we can limit this inner view to display only 1 result.

I do not see any other way to group the post by author.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.