Yii Dataprovider ASC order with reverse output - php

I'm using Yii's dataprovider + listview now. I'm using this for a mailbox like Facebook. However, I noticed that facebook's mailbox order is neither regular ASC or DESC, it's actually ASC with an inverse order. Like all the conversation is in ASC order but when it comes to page view, you see the last page(newest) first and if you scroll up, you see like next(last) page with order record in ASC order.
How should I do this in Yii's data provider? Since if I get ASC order, my first page will be the oldest page but not newest.
Thanks for your help!

It is better to show some code we can work with in answering your question; but I shall take the shotgun approach and see if I can answer this.
return new CActiveDataProvider('Mail', array(
'criteria' => $criteria,
'sort' => array(
'defaultOrder' => 'delivery_time DESC',
),
));
Reference

Related

WordPress - Order posts by custom fields (PHP)

I would like to order my posts primarily by 'start_date', and secondly by 'start_time' (for posts that have the same 'start_date'). I only know how to order one or the other. Please help!
try adding it after a comma,
=> 'start_date, start_time',

Creating (Complex?) Custom Queries for Wordpress compatible with Visual Composer

I'm struggling to make two custom queries for visual composer:
a query which will display posts which are published with a date after today's date (have plugin which publishes future posts) in Ascending or descending order (whichever makes it show the soonest upcoming event first)
a query which will display only posts which meet multiple category requirements (eg. categories 'upcoming' and 'class' or 'upcoming' and 'social'
Really, either of these should give me the results I want, but the first would be most convenient.
I can't for the life of me decipher the Codex's page on custom queries and figure out how to get them to work outside of the context of a php page, and in the context of the visual compose.
One thought I had is that perhaps I need to add a custom query to my functions.php that has a name, and then call the query with the variables from Visual Composer? Is that the right idea? How would I do such a thing/call the new query?
I've tried the following to satisfy #1 and it seems to have disregarded the query altogether and just displayed all the events:
[vc_basic_grid post_type="custom" grid_id="vc_gid:1473741223498-3776c0d3-292b-4" custom_query="WP_Query( ''showposts=20&monthnum=' . date_query( array( 'after', . NOW() . ) ) . '&order_by=date&order=DESC')"]
[vc_separator]
[vc_basic_grid post_type="custom" grid_id="vc_gid:1473741223504-67e7758b-8892-6" custom_query="$args = array(
'date_query' => array(
array(
'after' => NOW(),
'inclusive' => true,
),
),
'posts_per_page' => -1, 'order_by' => 'date', 'order' => 'ASC'
);
$query = new WP_Query( $args );"]
Would love some nudges in the right direction!
Thank you :)
I did something similar not too long ago and used the following as far as the date & making sure it only pulled posts from "today" and in the future.
_EventStartDate=>$today
That was for pulling upcoming events for a custom post type. With that said, this code is for your scenario which is retrieving normal posts:
date=>$today
Here's my whole custom query that works to pull events but I'm stuck on trying to figure out how to pull from multiple categories as well:
post_type=tribe_events&tribe_events_cat=featured&post_status=publish&_EventStartDate=>$today&orderby=_EventStartDate&order=asc
Please follow up once you have a solution.

Ordering by multiple meta keys wordpress

Im aware there are several posts relating to this issue but i am yet to find a fix for my current problem.
Im reasonably new to Wordpress and am still getting used to it, however...
The Problem
I'm implementing a front end sorting system for users to filter out schools, i am using a rating plugin (comment rating field pro) and the issue i have is that when users sort by star rating i also want it to sub sort by number of reviews (comments). Currently it is only sorting by rating and simply ignoring the number of comments and sorting by title. I have tried various combinations of query parameter arrays such as meta_query and multiple meta keys but the issue appears to be that it refuses to sort the second value. Both are numbers in the database.
TL:DR it needs to sort by stars and then by number of reviews.
Unfortunatly a custom query is out of the question as the array is being fed into another plugin which appears to only accept an array of args.
This is the sort of idea im going for (this does not work)
Array ( [post_type] => surf-school [posts_per_page] => 12 [paged] => 0 [meta_key] => crfp-average-rating [orderby] => meta_value crfp-total-rating [order] => DESC )
Any help would be greatly appreciated as its driving me insane!
Thanks in advance.
Update
I have managed to fix this using from a comment reply to this post which now appears to have been deleted :(
I managed it by adding a filter to wp_query and forcing a custom order by as seen here Plugin API/Filter Reference/posts orderby - Codex
function edit_posts_orderby($orderby_statement) {
$orderby_statement = "wp_postmeta.meta_value DESC, wp_posts.comment_count DESC";
return $orderby_statement;
}
placed in functions.php and
add_filter('posts_orderby', 'edit_posts_orderby');
placed just before the query. Hope this helps someone else :)

Cakephp, order find by related model field

I have a News model that has many Comments. What I need is to find ten News that has new Comments.
At first this task is seems to be eazy, I just need to find last ten Comments ($this->Comment->find('all');) and just display related News, but in case I have 2 comments for the same news I will recieve a duplicated news entry.
So, can I order News by Comments date or something?
*And here is solution. Thanks Dave
$this->Comment->find('all', array(
'order' => array(
'Comment.created' => 'DESC'
),
'group' => 'News.id',
));
Use MySQL's "GROUP BY" ('group' option in CakePHP). More details:
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions

How to use a relationship in the where parameter when finding records using the pods framework?

my question has to do with the pods framework plugin for wordpress sites. I am using pods version 2.2 and have been having trouble with the where parameter in the find() function.
I'd be suprised if I am the first person to encounter this problem but I have searched extensively and haven't found anyone providing an answer (or question at that).
Anyway, I'll give an example to highlight my problem.
Say I have a Bands Pod and a Records Pod and these two pods have a bi-directional multi-select relationship between them (that is, an n to n relationship). Hence a band can have numerous records and a record can have multiple bands. Further, the relationship exists between the fields BandsPod('records') and RecordsPod('bands').
Now, I can retrieve all records in the records pod like so (note the where is commented out):
$pods = pods('records');
$params = array(
'select' => 't.*',
'limit' => -1
//,'where' => '???'
);
$pods->find($params);
Then do whatever I want with them, e.g. template(), fetch(), etc.
My trouble occurs when I want to filter by band. What should my where statement be if I want to retrieve all records by band with id 1?
My view is that it should be something like this:
$params = array(
'select' => 't.*',
'limit' => -1,
'where' => '1 IN bands.id'
);
$pods->find($params);
However, this does not work (not that I especially expected it to).
It would also be desirable to know how this would work for filtering by multiple bands. E.g.
'where' => '(1, 2) IN bands.id'
As I said before, I've been trying to get this to work for some time and with little joy. I have managed to get it working but in a very ugly way. I.e.
Get bands from Bands Pod with relevant band ids,
Collect all ids of records from the bands pod records field,
Write params for Records Pod
Use the ids in the where statement to check they match with t.id,
$pods->find(); //where $pods=pods('records');
Thanks in advance for taking the time to read this and any answers you may give.
Cheers,
Joe
N.B. I know about the filters() function and it does not do what I'm after. I'd like stuff specifically for the where statement please.
You would want:
'where' => 'bands.id IN ( 1, 2 )'
If your bands are a custom post type, it would be:
'where' => 'bands.ID IN ( 1, 2 )'

Categories