Yes i realise that, i have been trying to integrate parts of it but am struggling to get it to work successfully. i have tried a number of different ways getting different ideas from the code you provided but it never seems to work properly.
sorry i'm relatively new to php and i'm not sure how to integrate the code you have given me into the original code.
my original code returns a variable value and manages to get the highest value without sorting the data. can someone explain to me how this works or how to integrate the codes together so that when the variable data is inputted from the below code, i get the highest three percentages outputted in the same format as the $content in the original code.
$args = array(
'post_type' => 'funder', 'post_status' => 'publish', // optional 'posts_per_page' => -1 ); $lists = get_posts($args);
as you can see in the original code, $lists becomes the new array - or have i misunderstood something??
sorry if i'm horribly confusing!!!
will this return three values though.
for example if i had a=10/100, b=2/10, c=20/50, d=1.5/10, e=3/5, f=5/100, g=33/100
i want the function to return content as
e 60%
c 40%
g 33%
this data is obviously just random example data where it would be $total/$goal
in its current format it just returns
e 60%
what part of this code do i need to edit in order for the funder with the second highest percentage to be returned??
function get_donated_list() { global $post; $content = '';$args = array('post_type' => 'funder','post_status' => 'publish', // optional 'posts_per_page' => -1); $lists = get_posts($args);$highest=0;$highest_id=0; $completed = array();$i=0;if($lists) {foreach($lists as $list) {$list_id = $list->ID;$goal = $this->get_goal_amount($list_id);$total = $this->get_amount_raised($list_id);$percent=($total/$goal)*100; if($highest < $percent && $percent < 100 ){$highest = $percent;$highest_id = $list_id;}if($percent==100){$completed[$i] = $list_id;$i++;}}} if($highest_id){$content=get_the_title( $highest_id )." ".round($highest, 2).'%'; } return $content;}
i have tried changing a few parts in the code but it still returns the id witht the highest percentage
EDIT i have had a look around myself and i think what i actually want is a foreach with a limit of 3 loops but i don't know where to add it.
i want it to loop the process so that it returns the three highest percentages
one error in the code is:
if($percent==100) should have actually read if(0 < $percent)
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.