Support

Account

Home Forums General Issues Filter by one meta_value1, sort by another meta_value2

Helping

Filter by one meta_value1, sort by another meta_value2

  • Hello.

    I’m trying to find a solution for this challenge. I’m pulling in some posts based on an ACF field, “state” which value is obtained from the URL. That part works fine.

    Now, I’d like to find a way to sort $posts by “organization” which is also an ACF field. How can I filter results by one meta_value, and sort by another one? Every tip

    $state_from_URL = $_GET['state'];
    $posts = get_posts( array(  
    	'numberposts'	=> -1,
    	'post_type'	=> 'post',
    	'meta_key'	=> 'state',  
    	'meta_value'	=> $state_from_URL, 
    	'orderby'	=> 'organization',
    	'order'		=> 'ASC',
    ));

    I appreciate any help or tips!

  • This can be done using clauses like I outlined here https://support.advancedcustomfields.com/forums/topic/sort-by-one-field-and-then-by-another/#post-52147

    Edit: maybe not exactly like I outlined there, but the principle is the same and you should be able to do this using clauses.

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

The topic ‘Filter by one meta_value1, sort by another meta_value2’ is closed to new replies.