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

    You don’t have to follow the code on the page I gave you before. It’s only an example how to do it. I’m sorry I forgot to tell you that.

    The following is a simple example to do it.

    <?php if ( isset($_GET['searchkey']) ){ ?>
    
        <?php 
        // args
        $args = array(
            'numberposts'	=> -1,
            'post_type'	=> 'custom-post-type',
            'meta_query'	=> array(
                array(
                    'key'		=> 'athlete',
                    'value'		=> $_GET['searchathlete'],
                    'compare'	=> 'LIKE'
                )
            )
        );
    
        // query
        $the_query = new WP_Query( $args );
    
        ?>
        <?php if( $the_query->have_posts() ): ?>
            <ul>
            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                <li>
                    <a href="<?php the_permalink(); ?>">
                        <img src="<?php the_field('event_thumbnail'); ?>" />
                        <?php the_title(); ?>
                    </a>
                </li>
            <?php endwhile; ?>
            </ul>
        <?php endif; ?>
    
        <?php wp_reset_query(); ?>
    
    <?php } //endif isset searchkey?>

    Then you can get the posts like this:

    http://example.com/path-where-you-put-the-code/?searchathlete=searchkey

    Where “searchkey” is the athlete you want to search. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/.

    I hope this makes sense 🙂