【问题标题】:Display, sort and filter posts from a relationship field (Podscms)显示、排序和过滤来自关系字段的帖子 (Podscms)
【发布时间】:2013-09-26 12:57:47
【问题描述】:

我在 Wordpress 中使用 Pod 设置了一些自定义帖子类型,并使用关系字段将它们链接起来。现在我想显示(并链接到)来自单个帖子“postA”的相关自定义帖子“postB”。我也只想显示那些有未来日期的帖子,这些帖子也存储在“postB”的自定义字段中。

这是我目前得到的,放入主题模板文件(single-posta.php):

<?php
    $id = get_the_ID(); 

    $params = array( 
        'where' => 'postB.ID IN ('.$id.')',
        'limit'   => -1,  // Return all
        //'oderby' => 'postB.customDate, (order is not working, so I commented it out)
        //'order' => 'ASC'
    ); 
    $postsB = pods( 'postB', $params ); 

    if ( 0 < $postsB->total() ) { 
        while ( $postsB->fetch() ) {          
?>
            <p>
                <?php echo $postsB->display( 'title' ); ?><br>
               <?php echo $postsB->display( 'customDate' ); ?><br>
            </p>
<?php    
        }
    }
?> 

那我该怎么办

  • 排序结果?
  • 链接到这些帖子?
  • 将它们限制在未来的日期?

顺便说一句。这是获取这些帖子的正确方法吗?

【问题讨论】:

    标签: php wordpress relationship podscms


    【解决方案1】:

    您也可以使用 WP_Query,但由于您使用的是 Pods find() 语法,因此我将为您提供正确的代码:

    $params = array( 
        'where' => 'postB.ID IN ('.$id.')',
        'limit'   => -1,  // Return all
        'orderby' => 'customDate.meta_value ASC'
    ); 
    $postsB = pods( 'postB', $params );
    

    不过,Pods 不允许您创建带有大写字母的字段,所以很可能您是在 Pods 之外创建的,对吗?仔细检查一下,如果它是用 Pods 创建的,它将被命名为 'customdate'

    【讨论】:

    • 感谢您的帮助,效果很好!现在您能否告诉我如何过滤具有未来日期的帖子以及如何链接到他们的详细信息页面?顺便说一句,我更改了这篇文章的 cpt 名称,因为我的是德语,所以是的,它们实际上都是小写的。 ;-)
    • Pods.io 论坛上的交叉发帖:pods.io/forums/topic/…
    • 供将来参考,创建相关帖子链接的要点:gist.github.com/Shelob9/6679914
    猜你喜欢
    • 2016-11-04
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多