How can I make an array of variables generated using the values passed through a while loop ?
I am using osclass for a uni project and I find no way whatsoever to make a list os usable variables from the custom category fields I added.
I have made Identifiers for the custom categories also (SLUGs), and have tried many different approaches to grab and echo the custom category values elsewhere on the page.
I cannot isolate the custom category values by any means.
Below is the code used to display the custom category values on my osclass page
<?php if( osc_count_item_meta() >= 1 ) { ?>
<?php while ( osc_has_item_meta() ) { ?>
<?php if(osc_item_meta_value()!='') { ?>
// I WOULD LIKE TO MAKE MAKE AN ARRAY OF VERIABLES SO I CAN USE THE CUSTOM CATEGORY DATA
// TRIED SO FAR if(osc_item_meta_name()!='') { $caughtcountry = osc_item_meta_value('country'); }
// BUT THIS APPROACH DOES NOT WORK
<?php } ?>
<?php } ?>
<?php } ?>`
I have tried using the identifiers that I added to the category in Admin panel.
I have also tried using the current PHP but cannot grab the values of specific custom categories.
Below is an example of one of my attempts to grab a custom category value but it only shows the 1st value within the values instead of cataching the 'age' value using the 'age' identifier i used.
<?php if( osc_count_item_meta() >0 ) { // The If osc_count_item_meta() >=1
if(osc_item_meta_value('age')!='') { $caughtage = osc_item_meta_value('age'); } else { $caughtage=''; }
} else { $caughtage=''; }
?>
Also tried the following
<?php if( osc_count_item_meta() >0 ) {
if(osc_item_meta_name('age')!='') { $caughtage = osc_item_meta_value('age'); } else { $caughtage=''; }
} else { $caughtage=''; }
?>
Have also tried common sense but that doesnt work either
<?php if( osc_item_age()!='' ) { $Age = osc_item_age(); } else {$Age='';} ?>
I am completely stumped.
The code below loops through the custom categories but isolating them into variables im struggling with, yet I imagine it would be as easy as an array loop
<?php if( osc_count_item_meta() >= 1 ) { ?>
<div id="custom_fields">
<div class="meta_list">
<?php while ( osc_has_item_meta() ) { ?>
<?php if(osc_item_meta_value()!='') { ?>
<div class="meta">
<strong><?php echo osc_item_meta_name(); ?>:</strong>
<span><?php echo osc_item_meta_value(); ?></span>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
Any help would be greatly appreciated.
UPDATE: ( SOLVED - BUT STILL A PROBLEM )
Finallty Manged to grab the Values and pass inro a Variable, To Be Honest Lack Of Sleep Frustrated me and made me miss the obvious solution
<?php if( osc_count_item_meta() >= 1 ) { ?>
<?php while ( osc_has_item_meta() ) { ?>
<?php if(osc_item_meta_value()!='') { ?>
<?php $customData = osc_item_meta_name(); ?>
<? if ( $customData =="Gender") { $caughtGender = osc_item_meta_value(); } else { $cuaghtGender = ""; } ?>
<? if ( $customData =="Age") { $caughtAge = osc_item_meta_value(); } else { $cuaghtAge = ""; } ?>
<? if ( $customData =="Nationality") { $caughtNationality = osc_item_meta_value(); } else { $cuaghtNationality = ""; } ?>
<? if ( $customData =="Seeking") { $caughtSeeking = osc_item_meta_value(); } else { $cuaghtSeeking = ""; } ?>
<? if ( $customData =="Interests") { $caughtInterests = osc_item_meta_value(); } else { $cuaghtInterests = ""; } ?>
<? if ( $customData =="Pets") { $caughtPets = osc_item_meta_value(); } else { $cuaghtPets = ""; } ?>
<?php } ?>
<?php } ?> <!-- WHILE LOOP END -->
<?php } ?>
However having dont this. The next while loop of the same item_meta data isnt processed and shows no results. Does not throw any errors but just doesnt show any results. As though i have used the while loop and cant make another, Which is Odd to me..
How do i again make a While Loop that will show data and why does the 2nd loop not show data. I am egar to educate, thank you for any responces.
$all) which means if you know thatageshould exist then after the loop it can be accessed as$all['age']. If there is a possibility it does not exist then some validation would need to be performed after the loop to verify required parameters exist.