Forums › Forums › Search & Filter Pro › Custom Results Page – Order results by ACF value
- This topic has 4 replies, 2 voices, and was last updated 5 years, 2 months ago by
Trevor.
Viewing 5 posts - 1 through 5 (of 5 total)
-
Anonymous(Private) December 4, 2019 at 11:15 pm #228401
Hi There,
I’m trying to order my results page by a number field in ACF.Here’s where I am at with no luck – any suggestions welcome!
<?php /** * Search & Filter Pro * * Sample Results Template * * @package Search_Filter * @author Ross Morsali * @link https://searchandfilter.com * @copyright 2018 Search & Filter * * Note: these templates are not full page templates, rather * just an encaspulation of the your results loop which should * be inserted in to other pages by using a shortcode - think * of it as a template part * * This template is an absolute base example showing you what * you can do, for more customisation see the WordPress docs * and using template tags - * * http://codex.wordpress.org/Template_Tags * */ $query = get_posts(array( 'meta_key' => 'DST-carat', 'orderby' => 'meta_value', 'order' => 'DESC' )); if ( $query->have_posts() ) { ?> <div class="row"> <div class="col-12"> <table> <tbody> <?php while ($query->have_posts()) { $query->the_post(); ?> <tr> <td><?php the_field('DST-shape'); ?></td> <td><?php the_field('DST-carat'); ?></td> <td><?php the_field('DST-colour'); ?></td> <td><?php the_field('DST-clarity'); ?></td> <td><?php the_field('DST-fluorescence'); ?></td> <td><?php the_field('DST-lab'); ?></td> <td><a href="https://www.gia.edu/report-check?reportno=<?php the_field('DST-certificate'); ?>" target="_blank">GIA Certificate</a></td> <td>Make an enquiry</td> </tr> <?php } ?> </tbody> </table> </div> </div> Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> <div class="pagination"> <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php } else { echo "No Results Found"; } ?>
Anonymous(Private) December 5, 2019 at 12:14 am #228403EDIT:
$query = new WP_Query(array( 'post_type' => 'diamond_search_tool', 'posts_per_page' => -1, 'meta_key' => 'DST-carat', 'orderby' => 'meta_value', 'order' => 'ASC' ));
Displays content in intended but disables the filter.
Using Shortcodes.Trevor(Private) December 5, 2019 at 11:31 am #228434You should not be adding the query into the results.php file.
Instead use the Posts tab in the form design, and that has a sort option. Use Meta Value, select the ACF key name (make sure it DOES NOT start with an underscore) and then sort direction. See here an example:
https://www.screencast.com/t/rVKgFNJl7FD
Note, when you sort in this way, any post that has no value set will be excluded from the results.
-
AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)