Support

Account

Home Forums General Issues user to sort and filter ACF list Reply To: user to sort and filter ACF list

  • Hi @vince_m

    This will be hard to explain, so I’m sorry if I’m not clear enough. I’ll use the link you gave me for an example (https://swimming.ca/en/events-results/meet-results/?province=1&season=16&month=5). In that link, you can see the $_GET variables, which is “province=1&season=16&month=5”. You can get these variables by using this code:

    $province = $_GET['province'];
    $season = $_GET['season'];
    $month = $_GET['month'];

    With those variable, you can query the posts like this:

    $args = array(       
        'post_type' => 'result',
        'category_name' => 'results',
        'orderby' => 'date',
        'order'   => 'ACS',
        'posts_per_page'  =>  15,
        'paged' =>  $paged,
        'meta_query'    => array(
            'relation' => 'AND',
            array(
                'key' => 'province_custom_field',
                'value' => $_GET['province'],
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'season_custom_field',
                'value' => $_GET['season'],
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'month_custom_field',
                'value' => $_GET['month'],
                'compare' => 'LIKE'
            ),
        )
    );

    Where “province_custom_field”, “season_custom_field” and “month_custom_field” are the custom fields you want to filter.

    What you can do for now is trying to filter one custom field first instead of three in the same time. This will make sure that your code is working or not.

    Also, if you’re not familiar with programming, I suggest you learn it here: http://www.w3schools.com/php/. If you don’t have time to do it, you can always hire a developer to help you out with it, and I’d recommend looking for one on https://studio.envato.com/ or https://www.upwork.com/.

    I hope this makes sense 🙂