Popular post view widget, sort by + where clause

This topic contains 12 replies, has 3 voices, and was last updated by  Kiran 6 years, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #399798

    anders
    Full Member
    Post count: 121

    Hi,

    I have a CPT where I sort the listing page by a custom field of date type.
    With your help I was also able to include “upcoming” functionality so that no outdated items appear. https://wpgeodirectory.com/support/topic/event-schedule-functionality/

    Could you please help me achieve the same thing inside a widget?
    Currently I´m using the Popular post View -widget so I guess I would need to customize the “order by” + “where” clause for the query.

    Thanks!

    #399875

    Paolo
    Site Admin
    Post count: 31206

    The developers have been alerted and they’ll see if it is possible. They’ll let you know asap.

    Thanks

    #399944

    Kiran
    Moderator
    Post count: 7069

    Hi anders,

    Please provide us site admin & FTP credentials.
    I have to look into current functionally. If it is possible, i will provide you snippet to achieve that.

    Kiran

    #399946

    anders
    Full Member
    Post count: 121

    Thank you Kiran,

    Unfortunately I´m still only at localhost with this.
    But I´m using a basic child theme for Directory Starter, trying to customize a “Popular Post View” -widget that is placed inside the GD Home Left Section.

    I have created a CPT with the GD Custom Post Types -addon then added a custom field (Date type).

    Inside the widget I would like to sort by the added custom field of date type and only show upcoming items (where the added custom field is, today or later)

    Thanks!

    #399986

    Kiran
    Moderator
    Post count: 7069

    Hi anders,

    The widget filtering is used by many GD widgets. So i am not able to provide snippet without checking your custom code & fields.

    Kiran

    #400273

    anders
    Full Member
    Post count: 121
    This reply has been marked as private.
    #400374

    Kiran
    Moderator
    Post count: 7069

    Hi There,

    You forgot to provide FTP host.

    Use following code snippet and let us know how it goes.

    
    
    function _gd_custom_widget_listings_where_date( $where ) {
    	global $plugin_prefix, $gd_query_args_widgets;
    
    	$query_args = $gd_query_args_widgets;
    	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
    		return $where;
    	}
        
    	$post_type = 'gd_vinresa'; // Change post type here
    	$field = 'geodir_avresedatum'; // Change field name here
    
    	if ( !empty( $query_args['post_type'] ) && $query_args['post_type'] == $post_type ) {
    		$date_now = date( "Y-m-d" );
    		$date_param = isset($_REQUEST['archive']) ? '<=' : '>=';
    		$table = $plugin_prefix . $post_type . '_detail';
    		$where .= " AND $table.$field $date_param '$date_now' ";
    	}        
    
    	return $where;
    }
    add_filter( 'geodir_filter_widget_listings_where', '_gd_custom_widget_listings_where_date', 10, 1 );

    Kiran

    #400420

    anders
    Full Member
    Post count: 121
    This reply has been marked as private.
    #400606

    Kiran
    Moderator
    Post count: 7069

    Hi There,

    I have updated snippet for sorting listing in widget.
    Check and let us know.

    Kiran

    #400678

    anders
    Full Member
    Post count: 121
    This reply has been marked as private.
    #400798

    Kiran
    Moderator
    Post count: 7069

    The functions.php under child theme directory was overwritten and it has lost my changes. I updated file on 14th Oct and it shows recently edited on 15th.

    BTW i have added snippet again. Check and let us know.

    Kiran

    #400810

    anders
    Full Member
    Post count: 121
    This reply has been marked as private.
    #400837

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
Viewing 13 posts - 1 through 13 (of 13 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket