自然排序的Wordpress帖子标题(按字母顺序和数字顺序)? [英] Natural sort Wordpress post titles (alphabetically and numerically)?
问题描述
是否可以通过标题而不是字母顺序对新的Wordpress帖子查询进行标题排序?
Is there any possible way to sort a new Wordpress post query by the title, but numerically instead of alphabetically?
我有一些标题按字母顺序具有很多相同的名称,然后再有一个数字,因此当然,例如Wordpress将title12
放在title1
之前.
I have some titles that have a lot of the same name alphabetically, then have a number afterwards, so of course for example Wordpress is putting title12
ahead of title1
.
$args = array(
'orderby'=> 'title',
'order' => 'ASC',
);
$loop = new WP_Query( $args );
我知道我们具有此功能,可以按升序对标题进行排序,但是它不能像这样对标题进行排序:
I know we have this functionality to sort titles in ascending order, but it does not sort titles like that:
Title 1
Title 2
请让我知道我们是否可以使用WP查询吗? 感谢您的提前帮助:)
Please let me know if we any work around using WP query ? Thanks for your help in advance :)
推荐答案
尝试在上面的代码后立即添加:
Try adding this immediately after your code above:
usort($loop->posts, function($a,$b) {
return strnatcmp($a->title, $b->post_title);
});
这篇关于自然排序的Wordpress帖子标题(按字母顺序和数字顺序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!