I have created a hidden custom field with a php function as its value. Like so --

$value_rating = get_post_meta($Property_Id, 'vr', true);

<input type="hidden" name="vr" class="form-control hideit" value="<?php if ( class_exists( 'MRP_Multi_Rating_API' ) ) {
    MRP_Multi_Rating_API::display_rating_result( array(
            'rating_item_ids' => 2,
            'show_count' => false,
            'result_type' => 'value_rt',
'no_rating_results_text' => 'Not Rated'
    ) );
} ?>" /> 

This works so far ok, the only thing is, the text that is generated by the MRP function is dynamic depending on the post's current review rating. So the problem I am having is when the post's rating changes, the text echoed by MRP does not.

I had a similar question for another theory I was trying, so I took some code from there and tried this as well --

function search_ratings() {
 if( ! in_the_loop() )
        return $thevalue;

    if( 'property' !== get_post_type() )
        return $thevalue;

    $args = [
        'rating_item_ids'           =>  2,
        'show_count'                => false,
        'result_type'               => 'value_rt',
        'no_rating_results_text'    => 'Not Rated',
        'echo'                      => 0,

    if ( class_exists( 'MRP_Multi_Rating_API' ) ) 
        $thevalue .= MRP_Multi_Rating_API::display_rating_result( $args ); 


    return $thevalue;
$tvr = $thevalue;
 update_post_meta( $post_id, 'vr', $tvr );

With something like this --

 <input type="hidden" name="vr" class="form-control hideit" value="<?php echo $tvr; ?>" /> 

That didnt work as well. Since the reviews are generated from users leaving comments, I dont want it to be where the posts have to be constantly updated manually in order for the values to update.

So is there anyway to use my function to dynamically set the value for the hidden custom field?

  • Whats the usage of $value_rating? u have just got it through DB and use it no where! – Pmpr Dec 22 '15 at 1:49
  • @Trix I use it for my search query. I need it to just save to the database and "update itself" if the information (rating) in the posts changes. Hence the loop if statement. Do you have any suggestions to contribute? – Rich Dec 22 '15 at 2:11
  • This appears to be the same question as one you deleted about 5 hours ago (as of this comment). Please do not delete and repost questions. You may edit existing questions to add information and to make them more clear. – s_ha_dum Dec 22 '15 at 5:05
  • @s_ha_dum Yeah I am trying to have the end result do the same thing, I just wasnt sure if it was ok to change my whole question since my other question had to do with meta boxes on the backend and this one involves field I created within my frontend posting template. – Rich Dec 22 '15 at 5:28
  • If the two are different then no problem but you should also be very careful about deleting questions. Do that too much and it counts as "destruction of content". Take a look at the site's faq. – s_ha_dum Dec 22 '15 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.