Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress中的Post类型分类_Wordpress - Fatal编程技术网

wordpress中的Post类型分类

wordpress中的Post类型分类,wordpress,Wordpress,在我的wordpress页面中有post_type=portfolio,通过这段代码我可以得到每个帖子的类别: $terms = get_the_terms( $post->ID, 'portfolio_category' ); foreach ( $terms as $term ) { $draught_links[] = $term->name; } $on_draught = join( ", ", $draught_links ); 但它不能正常工作。它显示当前

在我的wordpress页面中有post_type=portfolio,通过这段代码我可以得到每个帖子的类别:

$terms = get_the_terms( $post->ID, 'portfolio_category' );

foreach ( $terms as $term ) {
    $draught_links[] = $term->name;
}

$on_draught = join( ", ", $draught_links );

但它不能正常工作。它显示当前职位的类别,以及之前所有职位的类别。如何修复它?

将此代码用于特定类别

<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 3 );


$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>

<?php the_title(); ?>
<?php the_content(); ?>


更改帖子编号和类别ID…

将此代码用于特定类别

<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 3 );


$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>

<?php the_title(); ?>
<?php the_content(); ?>


更改帖子编号和类别ID…

回答此问题可能需要更多的上下文。例如,这个代码是在“循环”中还是在它的外部?如果它在一个循环中考虑初始化代码< $DRAGUTTHOLLUN= ARRAY()/<代码>前面的代码>前缀($TATE $术语) @ USE622018,这看起来是一个很可能的原因。USER 622018它正在工作。谢谢;)回答这个问题可能需要更多的背景知识。例如,这个代码是在“循环”中还是在它的外部?如果它在一个循环中考虑初始化代码< $DRAGUTTHOLLUN= ARRAY()/<代码>前面的代码>前缀($TATE $术语) @ USE622018,这看起来是一个很可能的原因。USER 622018它正在工作。谢谢;)