【问题标题】:Using custom categories and custom posts types (Bones Theme)使用自定义类别和自定义帖子类型(骨骼主题)
【发布时间】:2014-04-28 16:25:13
【问题描述】:

下面的代码显示具有匹配“页面名称”和“类别 slug”的帖子。但我试图让它使用自定义分类法。如何将其合并到以下内容中? 我在我的函数文件中使用它:

function my_get_posts( $category_name )
   {
    // set the criteria 
    $args = array(
        'numberposts' => -1,
        'category_name' => $category_name,
        'post_type' => 'custom_type'
    );
    // return the object array of the posts.
    return get_posts( $args );
}

这在我的页面中

<?php
    $posts_returned = my_get_posts($post->post_name);

    foreach ($posts_returned as $post_returned) {

    $postlink = get_post_permalink($post_returned->ID);

?>

HTML HERE

<?php   } ?>

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    解决了

    function sherwood_get_posts( $category_name )
    {
        // set the criteria 
        $args = array(
            'numberposts' => -1,
            'post_type' => 'custom_type',
            'tax_query' => array(
                    array(
                    'taxonomy' => 'custom_cat', 
                    'field' => 'slug', 
                    'terms' => array($category_name))
                )       
        );
        // return the object array of the posts.
        return get_posts( $args );
    }
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2013-08-03
      • 2023-04-05
      相关资源
      最近更新 更多