Jump to content

Recommended Posts

Hi everyone, I've been scratching my head trying to figure out how to sort my geo my wp custom posts when searching by the address, I want to put it alphabetically (post ID) but I dont know where to put this code

I've created a new file in the search results folder called functions.php and also gone into the content file but I'm having no look. can anyone advise what I'm doing wrong?

Thanks, Matthew

"function gmw_sort_alphabetically( $args, $gmw ) {
 
    //replace the value 1 with the form ID that you want to sort
    if ( $gmw['ID'] == 2 ) {
        $args['orderby'] = 'post_title';
        $args['order']     = 'ASC';
    }
 
    return $args;
}
add_filter( 'gmw_pt_search_query_args', 'gmw_sort_alphabetically', 50, 2 );


here is also my content file

"

`<?php
/**
 * Posts locator "grid-gray" search results template file.
 *
 * This file outputs the search results.
 *
 * You can modify this file to apply custom changes. However, it is not recomended
 * to make the changes directly in this file,
 * because your changes will be overwritten with the next update of the plugin.
 *
 * Instead you can copy-paste this template ( the "gray" folder contains this file
 * and the "css" folder ) into the theme's or child theme's folder of your site,
 * and apply your changes from there.
 *
 * The custom template folder will need to be placed under:
 * your-theme's-or-child-theme's-folder/geo-my-wp/posts-locator/search-results/
 *
 * Once the template folder is in the theme's folder, you will be able to select
 * it in the form editor. It will show in the "Search results" dropdown menu labed with "Custom: ".
 *
 * @param $gmw  ( array ) the form being used
 *
 * @param $gmw_form ( object ) the form object
 *
 * @param $post ( object ) post object in the loop
 *
 * @package geo-my-wp
 */

?>
<!--  Main results wrapper - wraps the paginations, map and results -->
<div class="gmw-results-wrapper grid-gray gmw-pt-grid-gray-results-wrapper <?php echo esc_attr( $gmw['prefix'] ); ?>" data-id="<?php echo absint( $gmw['ID'] ); ?>" data-prefix="<?php echo esc_attr( $gmw['prefix'] ); ?>">

    <?php if ( $gmw_form->has_locations() ) : ?>

        <div class="gmw-results">

            <?php do_action( 'gmw_search_results_start', $gmw ); ?>
            <div class="gmw-results-message">
                <span><?php gmw_results_message( $gmw ); ?></span>
                <?php do_action( 'gmw_search_results_after_results_message', $gmw ); ?>
            </div>

            <?php do_action( 'gmw_search_results_before_top_pagination', $gmw ); ?>

            <div class="pagination-per-page-wrapper top" >
                <?php gmw_per_page( $gmw ); ?>
                <?php gmw_pagination( $gmw ); ?>
            </div> 

            <?php gmw_results_map( $gmw ); ?>

            <?php do_action( 'gmw_search_results_before_loop', $gmw ); ?>
        <div id="dina_course_filter" style="margin-top: 20px;" >
            <div class="ecs-posts elementor-posts-container elementor-posts   elementor-grid elementor-posts--skin-archive_custom facetwp-template">

                <?php
                while ( $gmw_query->have_posts() ) :
                    $gmw_query->the_post();
                    ?>

                    <?php global $post; ?>

<article id="<?php echo get_the_ID(); ?>" class="elementor-post elementor-grid-item ecs-post-loop post-<?php echo get_the_ID(); ?> td-course-article courses type-courses status-publish hentry" style="margin-bottom: 20px;">
    <div data-elementor-type="loop" data-elementor-id="551" class="elementor elementor-551 elementor-location-archive post-3670 courses type-courses status-publish hentry" data-elementor-settings="[]">
        <div class="elementor-section-wrap">
            <section class="elementor-section elementor-top-section elementor-element elementor-element-1246e96 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="1246e96" data-element_type="section" >
                <div class="elementor-background-overlay"></div>
                <div class="elementor-container elementor-column-gap-default">
                    <div class="elementor-row">
                        <div class="elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-f746e5a" data-id="f746e5a" data-element_type="column">
                            <div class="elementor-column-wrap elementor-element-populated">
                                <div class="elementor-widget-wrap">
                                    <div class="elementor-element elementor-element-a8ae857 elementor-widget elementor-widget-image" data-id="a8ae857" data-element_type="widget" data-widget_type="image.default">
                                        <div class="elementor-widget-container">
                                            <div class="elementor-image">
                                                <?php
                                                if(has_post_thumbnail()){
                                                    the_post_thumbnail();
                                                }else{
                                                    ?>
                                                    <img src="https://feellikegolf.co.uk/wp-content/uploads/2018/11/golf-wordpress-theme-13-300x200.jpg" class="attachment-medium size-medium" alt="">
                                            <?php    }?>
                                               
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-5b1b077" data-id="5b1b077" data-element_type="column">
                            <div class="elementor-column-wrap elementor-element-populated">
                                <div class="elementor-widget-wrap">
                                    <div class="elementor-element elementor-element-f516154 elementor-widget elementor-widget-theme-post-title elementor-page-title elementor-widget-heading" data-id="f516154" data-element_type="widget" data-widget_type="theme-post-title.default">
                                        <div class="elementor-widget-container">
                                            <h3 class="elementor-heading-title elementor-size-default"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-0169883 elementor-icon-list--layout-traditional elementor-list-item-link-full_width elementor-widget elementor-widget-icon-list" data-id="0169883" data-element_type="widget" data-widget_type="icon-list.default">
                                        <div class="elementor-widget-container">
                                            <ul class="elementor-icon-list-items">
                                                <li class="elementor-icon-list-item">
                                                    <span class="elementor-icon-list-text"><b> Club Name: </b><?php echo get_field('club_name') ?></span>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-aad294b elementor-widget elementor-widget-shortcode" data-id="aad294b" data-element_type="widget" data-widget_type="shortcode.default">
                                        <div class="elementor-widget-container">
                                            <div class="elementor-shortcode">
                                                <?php echo do_shortcode('[site_reviews_summary assigned_posts="'.get_the_ID().'" hide="bars,rating"]'); ?>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-d98d852 elementor-widget elementor-widget-shortcode" data-id="d98d852" data-element_type="widget" data-widget_type="shortcode.default">
                                        <div class="elementor-widget-container" style="margin: 10px 0;">
                                            <?php 
                                            $morelink = ' <a href=".the_permalink().">Know More</a>';
                                            echo wp_trim_words( get_the_content(), 12, $morelink); ?>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-73c8d90 elementor-widget__width-auto elementor-widget elementor-widget-heading" data-id="73c8d90" data-element_type="widget" data-widget_type="heading.default">
                                        <div class="elementor-widget-container">
                                            <span class="elementor-heading-title elementor-size-default">Starting From £ <?php echo get_field('weekday_price'); ?></span>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-4d45c5f elementor-widget__width-auto elementor-widget elementor-widget-heading" data-id="4d45c5f" data-element_type="widget" data-widget_type="heading.default">
                                        <div class="elementor-widget-container">
                                            <span class="elementor-heading-title elementor-size-default">Type: <?php echo get_field('course_type'); ?></span>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-784105d elementor-widget__width-auto elementor-widget elementor-widget-heading" data-id="784105d" data-element_type="widget" data-widget_type="heading.default">
                                        <div class="elementor-widget-container">
                                            <span class="elementor-heading-title elementor-size-default">Architect: <?php echo get_field('course_architect'); ?></span>
                                        </div>
                                    </div>
                                    <div class="elementor-element elementor-element-44e97ca elementor-widget elementor-widget-spacer" data-id="44e97ca" data-element_type="widget" data-widget_type="spacer.default">
                                        <div class="elementor-widget-container">
                                            <div class="elementor-spacer">
                                                <div class="elementor-spacer-inner"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</article>

                <?php endwhile; ?>
            </div>
        </div>

            <?php do_action( 'gmw_search_results_after_loop', $gmw ); ?>

            <div class="pagination-per-page-wrapper bottom">
                <?php gmw_per_page( $gmw ); ?>
                <?php gmw_pagination( $gmw ); ?>
            </div> 

            <?php do_action( 'gmw_search_results_end', $gmw ); ?>

        </div>

    <?php else : ?>

        <div class="gmw-no-results">
            <?php do_action( 'gmw_no_results_start', $gmw ); ?>

            <?php gmw_no_results_message( $gmw ); ?>

            <?php do_action( 'gmw_no_results_end', $gmw ); ?> 
        </div>

    <?php endif; ?>

</div>`

Edited by feellikegolf
Link to comment
https://forums.phpfreaks.com/topic/314624-geo-my-wp-sort-alphabetically/
Share on other sites

It sounds like you want to sort by geographical distance when searching address but by post ID when other fields are searched? If so there are a couple options - either you're doing the WP_Query call manually (the global $gmw_query variable makes me think this is the case) at which point check the search parameters and update the ORDER BY clause there. Or, this is hooked into a generic WP query at which point you'll want to use the posts_orderby hook to see if the post in question is a search and modify the ORDER BY clause appropriately.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.