Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Wordpress : Custom search page and search by title, content and tag
<?php
include('../../../../wp-config.php');
$keyword = $_GET['k'];
search($wpdb->get_results("SELECT * from wp_posts WHERE post_title LIKE '$keyword%'"), "Full keyword");
$keywords_split = explode(" ",$keyword);
for($i=0;$i<count($keywords_split);$i++){
search($wpdb->get_results("SELECT * from wp_posts WHERE post_title LIKE '$keywords_split[$i]%'") ,"Split keyword = '$keywords_split[$i]'");
search($wpdb->get_results("SELECT * from wp_posts WHERE post_content LIKE '%$keywords_split[$i]%'") ,"Split keyword = '$keywords_split[$i]' (Content)");
}
$tags = str_replace(" ","-",$keyword).",".str_replace(" ",",",$keyword);
$searchtags = new WP_Query(array('post_type'=>array('one','two','three') ,'tag' => $tags));
while($searchtags->have_posts()):
$searchtags->next_post();
echo '<li>' . get_the_title($searchtags->post->ID ) . ' tag</li> ';
endwhile;
function search($results,$mark){
foreach($results as $data){
if($data->post_status =='publish'){
echo '<li>#'.$data->ID.' '.htmlentities($data->post_title).' ('.$mark.')</li>';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.