Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

获得自定义文章 #19

Open
deepthan opened this issue Jan 28, 2018 · 0 comments
Open

获得自定义文章 #19

deepthan opened this issue Jan 28, 2018 · 0 comments

Comments

@deepthan
Copy link
Owner

首先摸一下你的自定义的类型,显示这样的连接

http://localhost/wp-admin/term.php?taxonomy=category&tag_ID=10&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory

下面的参数即使对应的

&post_type = post&  ,  taxonomy = category&, &tag_ID=10&
<?php
$args = array(
    'post_type' => 'post', //自定义文章类型名称,上面连接可以获得。
    'showposts' => 3 , //输出的文章数量,这个可以是缺省值,不用设置
    'tax_query' => array(
        array(
            'taxonomy' => '1',//自定义分类的名称
            'terms' => 10 // 上面显示的id
            ),
        )
    );
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post();?>
    <h3><?php the_title(); ?></h3>
    <p><?php the_content(); ?></p>
    <?php endwhile; wp_reset_query(); //重置query查询
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant