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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.