Jul/100
Including Custom Search Results In A WordPress Page
One website required certain pages to contain custom search results.
To do this I needed to have the following code. The main tricks here are to create a second query as well as the main page query using the WP_Query method, and that the parameter for such a query needs an s=… to let it know the phrase being supplied is a search term.
The get_post_meta() method allows extraction from the main page extra parameter list.
<?php
$query_string = get_post_meta($post->ID, ‘organism_class’, true) ;
$search = new WP_Query( "s=$query_string&showposts=5" ) ;
$search_posts = $search->query( "s=$query_string&showposts=5" ) ;
while ($search->have_posts()) : $search->the_post();
?>
<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
<?php the_content(); ?>
<?php endwhile; ?>
No comments yet.
Leave a comment
No trackbacks yet.