gpt4 book ai didi

mysql - 按 id 问题自定义模板顺序

转载 作者:行者123 更新时间:2023-11-29 03:18:23 24 4
gpt4 key购买 nike

我正在尝试按 ASC 顺序按 ID 对帖子进行排序,当我使用单个查询时我可以这样做,但是当使用数组查询时我无法按 ASC 顺序按 ID 对帖子进行排序我的代码如下所示

  <?php
$ourCurrentPage = get_query_var('paged');
$newposts = new WP_Query(array(
'category_name' => 'stock-market-basics',
'orderby' => 'ID',
'order' => 'ASC',
'paged' => $ourCurrentPage
));
?>
<?php
if ($newposts->have_posts()):
while ($newposts->have_posts()):
$newposts->the_post();
?>

//一些显示代码和关闭代码//

  <?php endwhile; else : ?>
<p><?php esc_html_e( 'Sorry, no results matched your criteria.' ); ?</p>
<?php endif; ?>

<li><?php
echo paginate_links(array(
'total' => $newposts->max_num_pages
));
?></li>

最佳答案

WordPress 按类别名称查询

<?php $args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args ); ?>


// Custom query.
$query = new WP_Query( $args );

// Check that we have query results.
if ( $query->have_posts() ) {

// Start looping over the query results.
while ( $query->have_posts() ) {

$query->the_post();

// Contents of the queried post results go here.

}

}

希望这对你有用。

关于mysql - 按 id 问题自定义模板顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50329653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com