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-
AuthorPosts
-
December 27, 2017 at 9:08 pm #410644
Is there a way to exclude listings with a certain package_id from the main loop on the listing page?
Thanks
December 28, 2017 at 3:44 am #410667Hi 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!
December 28, 2017 at 9:54 am #410703There 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
December 28, 2017 at 1:40 pm #410717I 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,
JamesDecember 28, 2017 at 3:52 pm #410725hmm, doing it on searches? Where exactly are u trying to show this?
Stiofan
December 28, 2017 at 4:27 pm #410729This reply has been marked as private.December 28, 2017 at 7:45 pm #410749wordfence 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
December 28, 2017 at 8:07 pm #410753I 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,
JamesDecember 29, 2017 at 12:14 pm #410831Hi 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
December 29, 2017 at 1:53 pm #410841Here 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, 18December 29, 2017 at 7:13 pm #410864Again 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; }
December 29, 2017 at 8:25 pm #410874Awesome, 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; }
January 2, 2018 at 10:45 am #411181Do you have advanced search installed? (are u sure u want to exclude them from search rather than making it a search option?)
Stiofan
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket