按自定义字段订购帖子 [英] order posts by custom field
本文介绍了按自定义字段订购帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个查询
$numposts = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=5&showposts='.$numposts.'&paged=' . $paged);
如何按自定义字段对帖子进行排序?
how to order the posts by custom field?
推荐答案
怎么样?
$customfield = "MyCustomFieldName";
$numposts = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=5&showposts='.$numposts.'&paged='.$paged.'&meta_key='.$customfield.'&
orderby=meta_value&order=DESC');
或者不是为了保存自定义字段而创建一个新变量,而是将其直接添加到查询中..
or instead of creating a new variable just to hold the custom field just add it straight into the query..
query_posts('cat=5&showposts='.$numposts.'&paged='.$paged.'&meta_key=mycustomfield&
orderby=meta_value&order=DESC')
这篇关于按自定义字段订购帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文