所以你可以通过分类标题来搜索帖子——自定义或其他。答案将出现在“tax_query“WP\\U查询的一部分。下面是一个根据您的需要改编的Codex示例:
<ul>
<?php
global $post;
$album_title = $_GET[\'album-title\'];
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 5,
\'tax_query\' => array( // NOTE: array of arrays!
array(
\'taxonomy\' => \'albums\',
\'field\' => \'name\',
\'terms\' => $album_title
)
)
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
UPDATE
我还没有对此进行测试,但从理论上讲,我认为它可以工作。要匹配任何包含“foot”的内容:
<ul>
<?php
global $post;
$album_title = $_GET[\'album-title\']; // say the user entered \'foot\'
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 5,
\'tax_query\' => array( // NOTE: array of arrays!
array(
\'taxonomy\' => \'albums\',
\'field\' => \'name\',
\'terms\' => $album_title,
\'operator\' => \'LIKE\'
)
)
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
希望有帮助!