1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trim wordpress meta_value

Discussion in 'PHP' started by SharingEngines, Mar 12, 2014.

  1. #1
    Hi,

    I have a script like this
    SEMrush
    <span class="featrate">'. get_post_meta($key="taq_review_score", true). get_post_meta($post->ID, $key, true). '</span> / 10'. '</td>
    PHP:
    In mysql database I have a "meta_key" --> "taq_review_score" and "meta_values" like 95.2222222222, 84.6666666667, 96.8888888889...

    My question is if is possible trim the "meta_values" to show numbers like 9.5, 8.4, 9,6...

    Table "taq_review_score"

    [​IMG]

    [​IMG]
    I need to show values like 9.7 instead of 97.4444444444 - 9.6 instead of 96.1111111111 and so one.




    Thank you for your help
     
    Solved! View solution.
    Last edited: Mar 12, 2014
    SharingEngines, Mar 12, 2014 IP
    SEMrush
  2. Tomve

    Tomve Active Member

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    70
    #2
    I would use round function - http://php.net/manual/en/function.round.php

    <span class="featrate">'. round(get_post_meta($key="taq_review_score", true)). get_post_meta($post->ID, $key, true). '</span> / 10'. '</td>
    
    PHP:
     
    Tomve, Mar 12, 2014 IP
  3. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Hi,

    Thank you already made it
    <span class="featrate">'. (get_post_meta($key="taq_review_score", true)). round(get_post_meta($post->ID, $key, true)/10, 1). '</span> / 10'. '</td>
    Code (markup):
    Now I have to divide to functions $rate/$count

    I have this code
     
      $count = get_post_meta( $post->ID , 'tie_users_num', true );
      if( !empty($rate) && !empty($count)){
      $total = (($rate/$count)/5)*100;
      $totla_users_score = round($rate/$count,2);
      }
    
    Code (markup):
    and I have try to make this, but didn't work

       <td align="center" class="sitesrow2 hideme"><span class="featrate">'. (get_post_meta($key="tie_user_rate", true)). round(get_post_meta($post->ID, $key, true)$rate/$count,2).  '</span> / 10'. '
    
    Code (markup):
    Thank you for your help
     
    Last edited: Mar 13, 2014
    SharingEngines, Mar 13, 2014 IP
  4. #4
    try change this
    ... ,true)).  round(get_post_meta($post->ID, $key, true)$rate/$count,2).  '</span ...
    PHP:
    for

    ... ,true)).  round(get_post_meta($post->ID, $key, true) . $rate/$count,2).  '</span ...
    PHP:
    there is change between get_post_meta() and $rate (dot) but I'm not sure if there has to be only this

    ... ,true)).  $totla_users_score.  '</span ...
    PHP:
     
    Tomve, Mar 13, 2014 IP
  5. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Thank you for your help
     
    SharingEngines, Mar 13, 2014 IP
  6. Tomve

    Tomve Active Member

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    70
    #6
    you're welcome
     
    Tomve, Mar 13, 2014 IP