phpwordpresssearch

Custom Post Meta Search Template


I'm struggling with getting wordpress to search custom post meta from a page template. I've looked all over the internet and can't seem to find anything that will work. No plugins seem to work either.

On my posts, I have the custom meta: "rate" and the value: "10" - Wordpress delivers no result when searching any of these.

I'd be very appreciated if someone could write me a searchpage.php page template or point me in the right direction (I'm not good with php).

Here's my current PHP code:

<?php 
/*
Template Name: Search Custom Meta
*/
?>

<?php get_header(); ?>
<div id="content">
<div class="container clearfix fullwidth">
<div id="left-area">

<?php query_posts('meta_value='.$s); ?>
<?php if (!empty($wp_query->posts)) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

</div> <!-- end #left-area -->
</div> <!-- .container -->
</div> <!-- #content -->
<?php get_footer(); ?>

Solution

  • You checking incorrect variable in if so try removing that one,

    query_posts('meta_value='.$s);    
    while ( have_posts() ) : the_post();
        echo '<li>';
        the_title();
        echo '</li>';
    endwhile;