【发布时间】:2015-05-11 11:56:37
【问题描述】:
被困在这个问题上好几天了,所以我想我会伸出援手。
我创建了两个自定义分类法,单客户端和双客户端。这些通过高级自定义字段填充特殊内容。
我要做的是创建一个自定义页面模板,它将这两个分类法连接起来并打印出两个自定义分类法的内容。
这适用于我的分类法之一:
<?php
$args=array(
'post_type' => 'singleclients',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_field('client1_img'); ?>
<h3><?php the_field('client1_name'); ?></h3>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
我已尝试按照 Wordpress Codex 的说明进行操作,但似乎无法正常工作。这是一个我认为可行的示例,但根本没有显示任何内容。
<?php
$args=array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'singleclients',
'field' => 'slug',
'terms' => 'singleclients'
),
array(
'taxonomy' => 'dualclients',
'field' => 'slug',
'terms' => 'dualclients'
)
)
);
$posts = get_posts( $args );
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_field('client1_img'); ?>
<p>print test content</p>
<h3><?php the_field('client1_name'); ?></h3>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
在这一点上真的很沮丧。任何人都知道我做错了什么以及为什么它不会打印出两种分类法?
【问题讨论】:
标签: php wordpress taxonomy custom-taxonomy