Replies: 0
Hello,
I am trying to build a query that searches through my custom post type ‘resource’, and displays anything similar. so if we have digital as a title and the user puts in digitals or misspells it they will be shown ‘Digital’.
I have this code, and if you only do d, or any part of the word up to the l so d-i-g-i-t-a-l. it will pull up digital but if you add in the s it does not display any results.
<?php $resource=htmlspecialchars($_GET["s"]); ?>
<?php $query = "
SELECT *
FROM $wpdb->posts
WHERE $wpdb->posts.post_title LIKE '%$resource%'
AND $wpdb->posts.post_type = 'resource'
ORDER BY $wpdb->posts.post_title
";
print_r($query);
$pageposts=$wpdb->get_results($query);
if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endforeach; ?>
<?php else : ?>
<div class="wrap">
<hr class="hr--transparent">
<h2>Nothing found</h2>
<hr class="hr--transparent">
</div>
<?php endif; ?>
Any ideas on how I can get the like to work in my query would be appreciated.
Thanks,
Aaron