Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi all,
I have a content type "Store" that has a field with geographical lat/long. Then I have a view that is showing the Stores sorted by the distance from the current User position (from the most near to the most far).
What I'm trying to achieve is to take the 10 most near Stores, and then shows randomly only 2 of them.
Basically I want to have a block that shows only 2 Stores randomly, but doing the random only among the 10 most near Stores from user's current position.
Is there a way to do it? I tryed everything but no luck.
Thanks in advance!
Comment | File | Size | Author |
---|---|---|---|
#4 | Screenshot from 2016-03-05 13:52:47.png | 4.74 KB | Nikhilesh Gupta |
#4 | Screenshot from 2016-03-05 13:52:24.png | 6.23 KB | Nikhilesh Gupta |
Comments
Comment #2
drupaljunior CreditAttribution: drupaljunior commentedAny solution for this?
Comment #3
Nikhilesh Gupta CreditAttribution: Nikhilesh Gupta at Melity commentedComment #4
Nikhilesh Gupta CreditAttribution: Nikhilesh Gupta at Melity commented@drupaljunior
After achieving the 10 most near Stores, perform the following actions:
1) In the view block for pager select "Display a specified number of items" and specify the items as 2.
2) Next in the sort criteria select "Global: Random" asc/desc.
By this your block can get randomly 2 stores from 10.
Comment #5
drupaljunior CreditAttribution: drupaljunior commentedHi Nikhilesh,
To achieve the "10 most near Stores" what I'm doing is:
- Sort Criteria --> Ascending by distance
- Display a specified number of items" = 10
Now how can I make your suggestions described at points 1) and 2) applied on top without overriding the conditions for "10 most near Stores"?
Many Thanks in advance.
Comment #6
Nikhilesh Gupta CreditAttribution: Nikhilesh Gupta as a volunteer and at Melity commentedThis can achieved by passing the output of view as input to another view. You have created a view to get "10 most near stores". Now use this as the input of another view, in that new view you should use sort random and items as 2.
Comment #7
drupaljunior CreditAttribution: drupaljunior commentedHi Nikhilesh,
Your explanation is clear from a Query point of view. I simply don't know where to click in view editor.
"This can achieved by passing the output of view as input to another view." - how can I do it?
"Now use this as the input of another view" - how can I do it?
Thanks.
Comment #8
Nikhilesh Gupta CreditAttribution: Nikhilesh Gupta as a volunteer and at Melity commentedYou cannot do this with your view editor. Programatically get the first view by "views_get_view('machine_name')" to a variable, then pass the filters to it. Following is a sample approch
Ex : $view = views_get_view('machine_name');
$view->display['default']->display_options['filters']['field_pay_geolocation_distance']['value']['latitude'] = $latitude_details['latitude'];
$view->set_display('block');
$view->is_cacheable = FALSE;
$view->execute();
Comment #9
drupaljunior CreditAttribution: drupaljunior commentedWhere to put this kind of code?
Comment #10
MustangGB CreditAttribution: MustangGB commentedClosing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.