• Hi,
    I need assistance in order to "plug" travelers' map with some custom page template I made.
    
    Probably the knowledge I need is more about the general functionning of wordpress, but I don't know where to look.
    Here is what I tried (below the query is an example that works) : a page that just lists titles of articles corresponding to some terms of two custom taxonomies.
    Below is a code that works (list titles).
    
    <?php
    get_header();
    $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') )
    ??? ??? ??? ??? ??? ??? ??? ??? ),
    ??? ??? ??? ??? ??? ??? ??? )
    ?? ??? ??? ??? ??? ? );
    ?if ( $query->have_posts() ) : while ( $query->have_posts() ) :
    ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? $query->the_post();
    ?>
    
    ?<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo($co.'? '.the_title()); ?></a></h2>
    
    ?<?php endwhile; ?>
    
    ?wp_reset_postdata();
    
    Now, instead of listing titles, I would like to show a map with the relevant marks (those corresponding to the articles resulting from my WP Query). I thought I could do this by using do_shortcode(...), like I do so on my landing page (and it works). But I couldn't figure out where to insert my shortcode in the above example, or how to "sew" both...
    
    Any idea that can help me ?
    
    Thank you in advance !

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Camille V

    (@socrapop)

    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]' );


    Plugin Author Camille V

    (@socrapop)

    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

    Thread Starter agthalim

    (@agthalim)

    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 !

    Thread Starter agthalim

    (@agthalim)

    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!
    Plugin Author Camille V

    (@socrapop)

    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 ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘use a map for some custom WP_Query’ is closed to new replies.