I want to query with keywords and display some related posts on custom taxonomy page, the related posts comes from a custom post type “gift”. I have tried the code below, but it only worked for default post_type, how to make it to work for custom post_type? Many thanks!
<?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().
}
?>