繁体   English   中英

从自定义帖子类型获取所有帖子

[英]Get all posts from a Custom Post Type

我正在使用WP Types插件,并且一切正常,现在我需要显示通过该插件创建的内容,这就是我的工作方式:

$args = array(
    'posts_per_page'   => 15,
    'category_name'    => 'legislacion',
    'orderby'          => 'post_date',
    'order'            => 'DESC',
    'post_type'        => 'post',
    'post_status'      => 'publish',
    'suppress_filters' => true
);

$legislacion_posts = get_posts( $args );
?>

<ul>
    <?php foreach ( $legislacion_posts as $post ) : setup_postdata( $post ); ?> ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endforeach;
    wp_reset_postdata(); ?>
</ul>

但是我没有得到该类别的帖子,为什么呢?

编辑

这是archive-legislaciones.php文件的内容:

<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Pages Template
 *
 *
 * @file           archive-legislaciones.php
 * @package        Responsive
 * @author         Emil Uzelac
 * @copyright      2003 - 2013 ThemeID
 * @license        license.txt
 * @version        Release: 1.0
 * @filesource     wp-content/themes/responsive/page.php
 * @link           http://codex.wordpress.org/Theme_Development#Pages_.28page.php.29
 * @since          available since Release 1.0
 */
?>
<?php get_header(); ?>
<?php if ( is_page( 'legislaciones' ) ) { ?>
    <div id="content" class="grid col-620">
    <?php
    $args = array(
        'posts_per_page'   => 15,
        'category_name'    => 'legislacion',
        'orderby'          => 'post_date',
        'order'            => 'DESC',
        'post_type'        => 'post',
        'post_status'      => 'publish',
        'suppress_filters' => true
    );

    $legislacion_posts = get_posts( $args );
    ?>

    <ul>
        <?php foreach ( $legislacion_posts as $post ) : setup_postdata( $post ); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endforeach;
        wp_reset_postdata(); ?>
    </ul>
    </div>
    <?php get_sidebar(); ?>
<?php } ?>
<?php get_footer(); ?>

那里有什么问题吗?

这条线一定是这样的

<?php foreach ( $legislacion_posts as $post ) : setup_postdata( $post ); ?>

您必须删除最后一个吗?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM