我想用关键字查询并在自定义分类页面上显示一些相关帖子,相关帖子来自自定义帖子类型“gift”。我尝试了下面的代码,但它只适用于默认的post\\u类型,如何使其适用于自定义post\\u类型?非常感谢!
<?php
$querytitle = $reltopic; //$reltopic is query keywords
$querytitle=strtoupper($querytitle);
$ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE UCASE(post_title) LIKE \'%$querytitle%\' AND post_type=\'gift\' AND post_status=\'publish\'");
if ($ids) {
$args=array(
\'post__in\' => $ids,
\'posts_per_page\' => -1,
\'caller_get_posts\'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
//echo \'List of Posts\';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" target="_blank"><?php the_title(); ?></a>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
}
?>