【发布时间】:2019-03-05 13:10:35
【问题描述】:
我有一个高级自定义,输出一个选择的分类,我试图将它传递到 WordPress 循环内的一个数组中。
显示我的自定义帖子类型的特定分类的循环在这里:
<?php
$loop = new WP_Query( array(
'post_type' => 'portfolio',
'portfolio_category' => 'social-media-marketing',
'posts_per_page' => -1,
)
);
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php endwhile; wp_reset_query(); ?>
我想用自定义帖子类型的结果替换投资组合类别,以便用户可以选择要显示的分类。
我必须在高级自定义字段分类中提取的代码在这里:
<?php
$term = get_field('portfolio_category');
if( $term ): ?>
<h2><?php echo $term->slug; ?></h2>
<?php endif; ?>
这两个代码位单独工作。我试过像这样一起运行它们:
<?php
$term = get_field('portfolio_category');
$loop = new WP_Query( array(
'post_type' => 'portfolio',
'portfolio_category' => 'echo $term->slug;',
'posts_per_page' => -1,
)
);
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php endwhile; wp_reset_query(); ?>
还有其他一些东西,但我似乎无法让它显示任何东西......我做错了什么??
【问题讨论】:
标签: php wordpress custom-post-type advanced-custom-fields