【问题标题】:Wordpress sort custom field values in alphabetical orderWordpress 按字母顺序对自定义字段值进行排序
【发布时间】:2013-10-25 06:09:00
【问题描述】:

我正在使用 WordPress 自定义内容类型管理器来构建文学机构网站。

我停留在的页面是作者页面,其中显示了与作者相关的所有书籍的缩略图。我下面的代码就是这样做的,但是我希望它按字母顺序显示。这是代码:

<?php if (get_custom_field("authimage:get_post")):?>
<div class="thumbstrip">
<h4>Titles by this Author</h4>
<ul>
<?php $my_post = get_custom_field("authimage:get_post");
    if(!empty($my_post)){
        foreach ($my_post as $a) {
            print '<li><a href="'. $a['permalink'] .'" title="'. $a['post_title'] .'"><img src="'.$a ['thumbnail_src'].'" /></a></li>';
        }
    }
?>
<ul>
</div>
<?php endif;?>

我到处搜索,但很难将解决方案适应我现有的代码。

【问题讨论】:

    标签: wordpress sorting custom-fields alphabetical


    【解决方案1】:
    <?php 
    $args=array(
          'meta_key' => 'authimage',  
          'orderby' => 'meta_value',
          'order' => 'ASC',
          'numberposts' => 99
        );
        $thePosts = get_posts($args);
        $i=1;
        foreach($thePosts as $thisPost){
            $getPost = get_post($thisPost->ID);
             //Whatever you want to do with the post
        }
    ?>
    

    【讨论】:

    • 出于某种原因,显示缩略图的部分变为空白。我对此有点陌生。我需要知道如何将任何解决方案合并到我现有的代码中。如果您可以向我展示包含我的代码,那就太好了。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多