加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – WordPress – 获取所有数据和排序

发布时间:2020-12-13 16:50:23 所属栏目:PHP教程 来源:网络整理
导读:我正在使用Wordpress.我有以下查询从数据库中获取数据,它是完美的工作 $args1 = array( 'post_type' = 'gallery','posts_per_page' = $gnum,'post__in' = array(400,403),'paged' = $paged,'orderby' = 'title','order' = 'ASC' );query_posts($args1);?php
我正在使用Wordpress.我有以下查询从数据库中获取数据,它是完美的工作

$args1 = array(
 'post_type' => 'gallery','posts_per_page' => $gnum,'post__in' => array(400,403),'paged' => $paged,'orderby' => 'title','order' => 'ASC'                    

);

query_posts($args1);

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

//And then some other code to display data

使用’post__in’=>数组(400,在上面的查询中,我正在获取ID =’400’和’403’的行.所以当我回声时,我只能看到两个信息.

现在,我想要实现的是从表中获取所有数据,但是当我显示信息时,我想先得到ID为400的行,然后是403,然后根据’orderby’=>得到其余的行. ‘title’,”order’=> ‘ASC’

你能帮忙查询一下吗?

谢谢

编辑

$args2 = array(
 'post_type' => 'gallery','post__not_in' => array(400,'order' => 'ASC'                    

);

query_posts($args2);

解决方法

不确定这是否适用于query_post参数,但它补充了有效的SQL.尝试:

$args = array(
 'post_type' => 'gallery','orderby' => 'case when ID in (400,403) then -1 else title end,title','order' => 'ASC'                    
);

query_posts($args);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读