Exclude Listings

This topic contains 12 replies, has 3 voices, and was last updated by  Stiofan O’Connor 7 years, 2 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #410644

    James Gehring
    Expired Member
    Post count: 34

    Is there a way to exclude listings with a certain package_id from the main loop on the listing page?

    Thanks

    #410667

    Kor
    Moderator
    Post count: 16516

    Hi James,

    This isn’t something that is currently possible out of the box. But I’ll forward this to a developer for a second opinion.

    Thanks!

    #410703

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    There is not settings for this but it could be done via hooks, but i’m not sure i get why you are doing it?

    Thanks,

    Stiofan

    #410717

    James Gehring
    Expired Member
    Post count: 34

    I have built a custom directory that has the listings in tiers. I created custom loops for each plan and left the free one with the original loop. I used a sort filter to make all the free listings come up first, but on some searches, there are not that many listings so the paid listings show up again. If you can point me to the filter that allows me to exclude all but the free packages, that would be great.

    Thanks,
    James

    #410725

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    hmm, doing it on searches? Where exactly are u trying to show this?

    Stiofan

    #410729

    James Gehring
    Expired Member
    Post count: 34
    This reply has been marked as private.
    #410749

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    wordfence is blocking my location (UK).

    But if you want to filter by GD custom fields you will need to do a custom query not a standard WP loop. If you install something like “Query monitor” plugin it will show u the current main queries to give you an idea.

    Thanks,

    Stiofan

    #410753

    James Gehring
    Expired Member
    Post count: 34

    I unblocked the UK.

    Let’s say I haven’t done any customization and just want to exclude listings with a package_id = 2 from the main listings page is there a filter for this? I know with geodir_posts_order_by_sort_my_change you can change the sort option by package_id, but I want to exclude them altogether. I was hoping for an easy solution so I wouldn’t have to do any more custom queries. =)

    That plugin is the one I used to help build my custom queries.

    Sorry to be a pain.

    Thanks,
    James

    #410831

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi James,

    Not tested but something like this:

    
    
    add_filter( 'posts_where' , '_my_post_exclude_where' );
    function _my_post_exclude_where($where)
    {
        global $wp_query,$table_prefix;
        $post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : '';
        $post_types = geodir_get_posttypes();
        if ($post_type && in_array($post_type, $post_types)){
            $where .= " AND ".$table_prefix.$post_type."_detail.package_id != 2 ";
        }
    
        return $where;
    }

    Thanks,

    Stiofan

    #410841

    James Gehring
    Expired Member
    Post count: 34

    Here is the query on the page. You can see that did not make any changes to the query.

    SELECT SQL_CALC_FOUND_ROWS iV5L4_posts.*, iV5L4_geodir_gd_place_detail.*
    FROM iV5L4_posts
    INNER JOIN iV5L4_geodir_gd_place_detail
    ON (iV5L4_geodir_gd_place_detail.post_id = iV5L4_posts.ID)
    WHERE 1=1
    AND ( ( iV5L4_posts.post_title LIKE “” )
    OR FIND_IN_SET(275 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(277 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(278 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(279 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(280 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(283 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(287 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(288 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(289 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(291 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(292 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(294 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(295 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(298 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(300 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(302 , iV5L4_geodir_gd_place_detail.gd_placecategory)
    OR FIND_IN_SET(303 , iV5L4_geodir_gd_place_detail.gd_placecategory) )
    AND iV5L4_posts.post_type in (‘gd_place’)
    AND (iV5L4_posts.post_status = ‘publish’)
    AND ( FIND_IN_SET(‘275’, iV5L4_geodir_gd_place_detail.gd_placecategory ) )
    ORDER BY iV5L4_geodir_gd_place_detail.package_id asc, iV5L4_geodir_gd_place_detail.is_featured asc, iV5L4_posts.post_date desc, iV5L4_posts.post_title
    LIMIT 0, 18

    #410864

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Again not tested but try replacing it with this:

    
    
    add_action('pre_get_posts', '_my_geodir_listing_loop_filter', 2);
    
    function _my_geodir_listing_loop_filter($query){
    if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] && !is_admin()) {
    add_filter( 'posts_where' , '_my_post_exclude_where' );
    
    }
    
    return $query;
    }
    function _my_post_exclude_where($where)
    {
        global $wp_query,$table_prefix;
        $post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : '';
        $post_types = geodir_get_posttypes();
        if ($post_type && in_array($post_type, $post_types)){
            $where .= " AND ".$table_prefix.$post_type."_detail.package_id != 2 ";
        }
    
        return $where;
    }
    #410874

    James Gehring
    Expired Member
    Post count: 34

    Awesome, I did have to modify it to work. Now how to get it to work when doing a search.

    
    
    add_action('pre_get_posts', '_my_geodir_listing_loop_filter', 2);
    
    function _my_geodir_listing_loop_filter($query){
    if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] && !is_admin()) {
    add_filter( 'posts_where' , '_my_post_exclude_where' );
    
    }
    
    return $query;
    }
    function _my_post_exclude_where($where)
    {
        global $wp_query,$table_prefix;
        $post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : '';
        $post_types = geodir_get_posttypes();
        if ($post_type && in_array($post_type, $post_types)){
            $where .= " AND ".$table_prefix."geodir_".$post_type."_detail.package_id != 2 ";
        }
    
        return $where;
    }
    #411181

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Do you have advanced search installed? (are u sure u want to exclude them from search rather than making it a search option?)

    Stiofan

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
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount