nad33m
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Sequential selection from arrayfunction getNextLetter(){ $alphabet = array ('A', 'B', 'C, 'D'); $letterKey = LetterKey; $recIndex = 0; if(get_option( $letterKey ) !== false){ $recIndex = get_option( $letterKey ); $updateNextIndex = ($recIndex+1) < count($alphabet) ? ($recIndex+1) : 0; update_option($letterKey, $updateNextIndex); return $alphabet[$recIndex]; }else{ add_option($letterKey, 1); return $alphabet[$recIndex]; } }
So I got it to work using the above code, each time the function is called it returns the next letter, and starts from the beginning when it returns the last letter.
$letterKey is stored in the database, which holds the last letter position.
Hope that will help anyone needing similar code. Probably could of been coded more elegantly, but it works, so my problem is solved.
A big thank you to bcworkz for pointing me in the right direction.
Forum: Developing with WordPress
In reply to: Sequential selection from array@bcworkz Thank you so much. The part about not needing the internal pointer now makes it simpler. With your answer I am confident I can now write the new code. I will report back with results and my final code.
Forum: Developing with WordPress
In reply to: Sequential selection from array@bcworkz thanks, I have thought about doing it this way, need help advancing the pointer, and return to zero when at the end of the array:
add_option( 'last-letter-key', 0 ) <--Adds new database variable -->
$last_key = get_option( 'last-letter-key' ); <--Retrieves last key from database --> $letter = $alphabet[$last_key]; <--sets letter using $last_key --> $letter = next($alphabet); <-- advances to next name --> <---here is where I think I need to put a loop to advance the pointer, what code goes here? --> $last_key = key($alphabet); <-- gets new key that is +1 now --> update_option( 'last-letter-key', $last_key ); <--saves new key to database -->
Just want to say Terry (plugin Author) contacted me personally to solve my problem, in fact there was no fault in the plugin itself.
The plugin works great and does exactly what is says it does, one click direct to cart and also an option to add a ‘continue shopping’ button on the product page.
Thanks for the great plugin.