Support » Fixing WordPress » Query a custom field's value from a custom post on the search template

  • Resolved donderhaas

    (@donderhaas)


    Hi,

    I have exhaustedly searched the forums and Google and somehow I am not finding a solution for what I am looking for as there are some variants of this out there, none of it has worked yet 🙁

    I have a custom post type. In the custom post type I have loads of custom fields (more than 20).

    I want to use query_posts to match the content in my posts with the custom_post_type and/or the meta_key and/or the meta_value on the search template. So basically I want to write a custom search that enables me to search through all the above.

    To start with I am happy to just focus on getting the meta_value (or meta_key) part working.

    If anyone can help or point me in the right direction I would be very thankful 🙂

    Code I am trying to use at the moment:

    <?php
    query_posts('meta_key=person_nickname&meta_value=john');
    ?>

    The code I am using to try and display the result:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; else: ?>
    <p>No results found for <?php echo $s?>.</p>
    <?php endif; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query a custom field's value from a custom post on the search template’ is closed to new replies.