I have full names as title posts and want to order it by the surname.
How could i do this with wordpress?
in PHP it would be along the lines of –
SELECT * from posts ORDER BY SUBSTR(LTRIM(post_title), LOCATE(' ',LTRIM(post_title)))
current code getting people category is;
$args = array(
'posts_per_page'=>50,
'cat'=> '39,-41',
'orderby'=>'title',
'order'=>'ASC',
);
query_posts($args);
how can i get that second word order?
best, Dan.
There is a filter, ‘posts_orderby’, which allows you to specify your own ORDER BY clauses. In your case, the code would look something like this:
Your first example is an SQL query, there is no native WordPress function that does this.
So that leaves you with some PHP options, explode it, str_word_count, along with sort (or ksort) to then arrange the array alphabetically.
This is a very odd way to use this type of data, it should be in a meta box, since you basically have to hack the query in your case to get what you want.