Forum Replies Created

  • Apologies it was set to private, I think you should be able to view it now

  • Hi Nixpix,

    This problem has been a stop-start issue for me. The above solution I’ve submitted does work (kind of) however I didn’t explain how the search function is working. If you can submit some details to me about your problem, what you’re inputting and trying to output it’ll help me offer you a solution.

    I’m a bit busy this week but when I get a chance I’ll create a post for you about what the whole search function is doing step-by-step.



  • Ok I think I’ve solved the solution (thanks to James from support too), leaving the answer here for anyone else, I used the documentation here to support it and :


    In the ACF back-end I changed the choices like this:

    January : January to 1 : January
    February: February to 2 : February

    Changing the key to a numeric value for sorting later. Now in the code I did this:

    	$args = array(
    		'post_type' => 'activities',
    		'posts_per_page'   => -1
    	$query = new WP_Query( $args );
    	// Create array of posts and fields
    	$myposts = get_posts( $args ); 
    	foreach ( $myposts as $key => $post ) : setup_postdata( $post );
    		$data['locations'][] = get_field('location');
    		$data['activity'][] = get_field('activity_type');
    		$data['difficulty'][] = get_field('difficulty');
    		// To sort months by the key value (not the label) get the field object - choice
    		// then grab the values like above
    		$monthField = get_field_object('availability');
    		$monthValue = get_field('availability');
    		// Get months, iterate through the choices
    		foreach($monthField as $month) {
    			$monthField['choices'][$monthValue] = $month;
    	// Omit duplicate results
    	foreach($data as $key => $value) {
    		$data[$key] = array_unique($data[$key]);
    	// sorted by alphabet
    	// sorted by the key

    And the html:

    	<select name='month'>
    				<option value='' disabled selected>Choose Month</option>
    					foreach($monthField['choices'] as $month) {
    						echo "<option value='{$month}'>{$month}</option>";

    Using the field object and using ksort solved the problem here, tested and seems to work well.

Viewing 3 posts - 1 through 3 (of 3 total)