Tagged: search results, term_id
- This topic has 3 replies, 2 voices, and was last updated 5 years, 6 months ago by
ivollaire.
-
AuthorPosts
-
November 28, 2016 at 7:14 am #55281
ivollaire
MemberHello! Thanks for the great plugin. It’s been exactly what we’ve needed up until one stumbling block we’ve found recently. We want to generate a map when a user first hits a page that only contains results from a certain term_id. In this case it’s specific categories. These pages will be the index page for the category so we only want the results from that category to show in the map and results.
I saw a similar question and used the code provided but it still isn’t working. For reference this is the code we’ve put in functions.php
1234567891011121314function gmw_gmap_set_default_taxonomy( $gmw ) {// abort if term_id is not setif ( empty( $gmw['params']['term_id'] ) )return $gmw;$gmw['page_load_results']['taxonomies']['usage'] = 'include';$gmw['page_load_results']['taxonomies']['tt_id'] = array( $gmw['params']['term_id'] );return $gmw;}// change the value 1 to the form IDadd_filter( 'gmw_default_form_values_1', 'gmw_gmap_set_default_taxonomy' );The shortcode being used is:
1do_shortcode('[gmw form="1" term_id="65"]');Eventually we’d also like to use:
1do_shortcode('[gmw map="1" term_id="65"]');Am I doing something wrong? Or maybe this is functionality that is added in a premium extension? Any help would be great.
Thanks!
December 5, 2016 at 10:45 pm #55297Eyal Fitoussi
MemberHello ivollaire,
The code you are referring to is meant to work with the Global Maps add-ons.You can do something similar, but using a different filter and it will require a custom functions to be added as well.
The filter you can use is gmw_pt_search_query_args and can be found in geo-my-wp/plugins/posts/includes/gmw-pt-search-query-class.
when using a custom function with this filter, the form object will pass to the function and the term_id value ( which you will pass via the shortcode ) can be retrieved using $gmw[‘params’][‘term_id’].
In short, try the script below ( change ‘category’ to your taxonomy ):
1234567891011121314151617181920212223function gmw_filter_results_by_term_id( $query_args, $gmw ) {// abort if no term_idif ( empty( $gmw['params']['term_id'] ) ) {return $query_args;}// modify the WP_Query args$query_args['tax_query'] = array(// include term_id from shortcode attribute. Can be multiple terms ID. comma separated.// change 'category' to your taxonomyarray('taxonomy' => 'category','field' => 'term_id','terms' => array( $gmw['params']['term_id'] ),'operator' => 'IN'));return $query_args;}add_filter( 'gmw_pt_search_query_args', 'gmw_filter_results_by_term_id', 50, 2 );Let me know if that helps.
December 18, 2016 at 2:32 pm #55338Eyal Fitoussi
MemberThis topic marked “Resolved” due to inactivity. If you wish to reply to this topic please change its status to “Not resolved” before replying.
December 19, 2016 at 6:21 am #55370ivollaire
MemberThanks for the response. The paid extension “Premium Settings” actually added the options I needed. I was able to generate separate forms for each term ID that work well enough for what we need.
-
AuthorPosts
You must be logged in to reply to this topic.