Adding post meta in search results

Forums › Forums › Search & Filter Pro › Adding post meta in search results

Viewing 5 posts – 1 through 5 (of 5 total)
  • Anonymous
    #30447

    I have customized the search results page to remove post summaries, by copying results.php into my theme template folder, and it’s working nicely. Now, I’d like to add a post meta field (“wp_review_total”) into the search results, so my display would look like:

    the_title
    ** post-meta-field **
    the_category
    the_tags

    Is this possible?

    Ross Moderator
    #30473

    Hey Ken

    Do you mean so that you list the current selection for hte wp_review_total field at the top of hte saerch results template?

    Then you would look here:
    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    Or do you mean, you would like to display the value for wp_review_total in your template next to each result?

    Then you would need this:
    https://developer.wordpress.org/reference/functions/get_post_meta/

    Thanks

    Anonymous
    #30514

    It would be for each search result. I tried following the second example, but got empty results:

    <?php $wp_review_total_values = get_post_meta( get_the_ID(),
     'wp_review_total', true ); ?>

    I’m not a PHP coder, so I’ll try playing with it some more. I may have missed something obvious.

    Ross Moderator
    #30515

    Hey Ken

    That looks like the right way to retrieve it – did you try echoing it out?

    <?php
    $wp_review_total_values = get_post_meta( get_the_ID(), 'wp_review_total', true );
    
    //echo out the values - should be ok because get_post_meta has the 3rd param set to true
    echo $wp_review_total_values;
    
    //alternatively dump the object to check whats inside:
    var_dump($wp_review_total_values);
    ?>
    Anonymous
    #30516

    Echoing the values worked! Thanks for your help.

Viewing 5 posts – 1 through 5 (of 5 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.