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

  • This topic has 4 replies, 2 voices, and was last updated 9 years ago by Anonymous.
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)