Dear @agthalim ,
Here is how current_query_markers works :
global $wp_query;
$cttm_global_query_args = $wp_query->query_vars;
$cttm_options_args = array_replace($cttm_global_query_args, array('nopaging' => true,
'tax_query' => array(
array(
'taxonomy' => 'cttm-markers-tax',
'field' => 'name',
'terms' => 'hasmarker',
),
),
));
What is does is it’s taking the global object $wp_query, takes its query_vars and modify them to fetch only the posts with markers. (custom private taxonomy cttm-markers-tax).
I think even if you succeed to change the global query post (with pre_get_post, I think it won’t work due to the fact that Travelers’ Map is overring the tax_query parameter :/
So your only solution for now is to use the shortcode with tax parameters.
Outside of your loop, so before the query or after wp_reset_postdata(), you should add the shortcode with your attributes, use the shortcode Helper in the plugin to create the custom attributes of the shortcode :
echo do_shortcode( '[travelers-map attribute=value]' );
I will add that the first solution would be possible if you don’t use tax_query but 'tag' => $tags and 'category_name' => $cats, but your taxonomies Algérie and Nucléaire would need to be native categories or tags
Dear Camille,
Thanks for your great reactivity !
Thank you for this answer. In effect, I had previously managed to use textual search, redefining search.php which used do_shortcode(…). But I need to build a page with checkboxes so that users can select the tax values they want to visualize.
Here’s the dirty soution I come up with :
- the global variable GLOBALS[myTheme][shortcode] is a string wirh the shortcode, initialized to show everything ;
- when the page is loaded, do_shortcode(GLOBALS[myTheme][shortcode]), so that the page shows the map ;
- with a javascript function, any click on a checkbox updates the shortcode sting in GLOBALS[myTheme][shortcode], and then opens the same url (so that the updated value of the global variable is used).
Do you think such a solution would work ? Do you have any better suggestion ?
What would be wrong with such a code as below ?
$query = new WP_Query(
array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'OR',
array ( 'taxonomy' => 'enjeu_environnemental', 'post_status' => array('publish'), 'field' => 'slug', 'terms' => array('nucleaire') ),
array ( 'taxonomy' => 'pays', 'post_status' => array('publish'), 'field' => 'slug', 'terms' => array('algerie') ),
array( 'taxonomy' => 'cttm-markers-tax', 'field' => 'name', 'terms' => 'hasmarker', ),
),
)
);
Thank you again !
Hi, (never mind my last question), let me sum up things, and explain what I tried :
What I want : a map and checkboxes corresponding to some custom taxonomy (let’s start with one) : the maps would show just the marks corresponding to the checked values of this taxonomy.
So far I did two things :
- added to the landing page checkboxes from which some javascript computes the shortcode which would correspond.
- added to my landing page a custom field myShortcode in which there is the shortcode used by the template to display the map (using do_shortcode(), following your advice : thank you!)
The original hope was to use the shortcode computed from the selected checkboxes to update the custom field and reload the page. But I cant’t find my way out of this. Would you have a suggestion ? Thank you in advance!
Hi again, sorry for my late reply I did not see your answer 🙂
I opened your website and saw you are reloading the page on category change. That’s a good thing, because I think what you are looking for in ajax is not possible.
If I remember well I tried it on a personal project, but never succeeded. The cause is that the markers are loaded with wp_localize_script which inject javascript variables to the page so the markers can load.
I’m not saying it’s impossible but it seems a lot of work for nothing important to me, a page refresh is not bad in that case 🙂