Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress-按元数据日期对post循环排序_Wordpress_Sorting - Fatal编程技术网

Wordpress-按元数据日期对post循环排序

Wordpress-按元数据日期对post循环排序,wordpress,sorting,Wordpress,Sorting,我有两个CPT,一个称为“艺术家”,另一个称为“发布”。我创建了一个单独的artist.php页面,显示艺术家及其“自定义元数据”。在同一页上,我用以下代码显示该艺术家的所有版本: <!-- GET RELEASES --> <?php $category = get_the_category(); $artist_name_slug = $category[0]->slug; $args = array ('post_type' => 'release', '

我有两个CPT,一个称为“艺术家”,另一个称为“发布”。我创建了一个单独的artist.php页面,显示艺术家及其“自定义元数据”。在同一页上,我用以下代码显示该艺术家的所有版本:

<!-- GET RELEASES -->
<?php

$category = get_the_category();
$artist_name_slug = $category[0]->slug;

$args = array ('post_type' => 'release', 'posts_per_page' => 20, 'category_name' => $artist_name_slug);

query_posts ($args);

?>

<?php if (have_posts()) : ?>
<h3 class="artist-col2-title">Releases</h3>
<?php while (have_posts()) : the_post(); ?>

<div class="artist-release"><a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php echo the_post_thumbnail('small'); ?></a></div>

<?php endwhile; ?>
<?php endif; ?>
<div style="clear:both;"></div>

释放
在发布CPT中,元数据中有发布日期


我想根据那个日期对发布进行排序,但我不知道如何将它添加到我的论点中。任何帮助都将不胜感激

要按元数据排序,可以使用

$args = array (
    'post_type' => 'release',
    'posts_per_page' => 20,
    'category_name' => $artist_name_slug,
    'meta_key' => 'your_meta_key' // i.e. release_date
    'orderby'='meta_value' // for numeric value use 'meta_value_num' instead
);
query_posts ($args);

但是请注意,要用于排序的查询中应该存在
meta_键。

用于存储日期的格式是什么?我认为这或多或少是一种标准的日期格式,这将使您无法使用标准的WordPress查询按元键对帖子进行排序。因此,您有两个选项:1)自定义SQL查询(不赞成,因为它可能无法向前兼容);2) 为所有“发布”帖子使用发布日期——这对您来说是个问题,而不是使用自定义字段吗?